-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WebView for WebUI-based tab strip
This is gated by both the buildflag |enable_webui_tab_strip| and a new kWebUITabStrip feature flag. The change adds toggle button and new-tab button next to the toolbar as well. This is still rough (has no animation, shows scroll bars), but checking this in should make it easier to iterate on. There are also placeholder icons and hard-coded colors in use for now. Bug: chromium:989131 Change-Id: I5bc2a20e85c8b98ca882d536f2f7937233304de1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1742934 Commit-Queue: Peter Boström <pbos@chromium.org> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org> Reviewed-by: Collin Baker <collinbaker@chromium.org> Reviewed-by: Tommy Li <tommycli@chromium.org> Cr-Commit-Position: refs/heads/master@{#686207}
- Loading branch information
Showing
17 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
chrome/browser/ui/views/frame/webui_tab_strip_container_view.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/ui/views/frame/webui_tab_strip_container_view.h" | ||
|
||
#include "base/logging.h" | ||
#include "chrome/app/chrome_command_ids.h" | ||
#include "chrome/app/vector_icons/vector_icons.h" | ||
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/task_manager/web_contents_tags.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_commands.h" | ||
#include "chrome/browser/ui/layout_constants.h" | ||
#include "chrome/browser/ui/view_ids.h" | ||
#include "chrome/browser/ui/views/toolbar/toolbar_button.h" | ||
#include "chrome/common/webui_url_constants.h" | ||
#include "ui/gfx/color_palette.h" | ||
#include "ui/gfx/paint_vector_icon.h" | ||
#include "ui/views/background.h" | ||
#include "ui/views/controls/webview/webview.h" | ||
#include "ui/views/layout/fill_layout.h" | ||
#include "ui/views/layout/flex_layout.h" | ||
#include "ui/views/view_class_properties.h" | ||
|
||
WebUITabStripContainerView::WebUITabStripContainerView(Browser* browser) | ||
: browser_(browser), | ||
web_view_( | ||
AddChildView(std::make_unique<views::WebView>(browser->profile()))) { | ||
SetVisible(false); | ||
SetLayoutManager(std::make_unique<views::FillLayout>()); | ||
web_view_->LoadInitialURL(GURL(chrome::kChromeUITabStripURL)); | ||
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | ||
web_view_->web_contents()); | ||
task_manager::WebContentsTags::CreateForTabContents( | ||
web_view_->web_contents()); | ||
} | ||
|
||
std::unique_ptr<views::View> | ||
WebUITabStripContainerView::CreateControlButtons() { | ||
auto toolbar_button_container = std::make_unique<views::View>(); | ||
toolbar_button_container | ||
->SetLayoutManager(std::make_unique<views::FlexLayout>()) | ||
->SetOrientation(views::LayoutOrientation::kHorizontal) | ||
.SetCrossAxisAlignment(views::LayoutAlignment::kCenter) | ||
.SetDefault(views::kMarginsKey, | ||
gfx::Insets(0, GetLayoutConstant(TOOLBAR_ELEMENT_PADDING))) | ||
.SetInteriorMargin( | ||
gfx::Insets(0, GetLayoutConstant(TOOLBAR_STANDARD_SPACING))) | ||
.SetCollapseMargins(true); | ||
toolbar_button_container->SetBackground( | ||
views::CreateSolidBackground(gfx::kGoogleGrey300)); | ||
|
||
ToolbarButton* const new_tab_button = toolbar_button_container->AddChildView( | ||
std::make_unique<ToolbarButton>(this)); | ||
new_tab_button->SetID(VIEW_ID_WEBUI_TAB_STRIP_NEW_TAB_BUTTON); | ||
new_tab_button->SetImage( | ||
views::Button::STATE_NORMAL, | ||
gfx::CreateVectorIcon(kAddIcon, gfx::kGoogleGrey700)); | ||
|
||
ToolbarButton* const toggle_button = toolbar_button_container->AddChildView( | ||
std::make_unique<ToolbarButton>(this)); | ||
toggle_button->SetID(VIEW_ID_WEBUI_TAB_STRIP_TOGGLE_BUTTON); | ||
// TODO(pbos): Replace this icon tab counter. | ||
toggle_button->SetImage( | ||
views::Button::STATE_NORMAL, | ||
gfx::CreateVectorIcon(kCaretUpIcon, gfx::kGoogleGrey700)); | ||
|
||
return toolbar_button_container; | ||
} | ||
|
||
void WebUITabStripContainerView::ButtonPressed(views::Button* sender, | ||
const ui::Event& event) { | ||
if (sender->GetID() == VIEW_ID_WEBUI_TAB_STRIP_TOGGLE_BUTTON) { | ||
// TODO(pbos): Trigger a slide animation here. | ||
SetVisible(!GetVisible()); | ||
InvalidateLayout(); | ||
} else if (sender->GetID() == VIEW_ID_WEBUI_TAB_STRIP_NEW_TAB_BUTTON) { | ||
chrome::ExecuteCommand(browser_, IDC_NEW_TAB); | ||
} else { | ||
NOTREACHED(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
chrome/browser/ui/views/frame/webui_tab_strip_container_view.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_WEBUI_TAB_STRIP_CONTAINER_VIEW_H_ | ||
#define CHROME_BROWSER_UI_VIEWS_FRAME_WEBUI_TAB_STRIP_CONTAINER_VIEW_H_ | ||
|
||
#include <memory> | ||
|
||
#include "chrome/common/buildflags.h" | ||
#include "ui/views/controls/button/button.h" | ||
#include "ui/views/view.h" | ||
|
||
#if !BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) | ||
#error | ||
#endif | ||
|
||
namespace views { | ||
class WebView; | ||
} // namespace views | ||
|
||
class Browser; | ||
|
||
class WebUITabStripContainerView : public views::View, | ||
public views::ButtonListener { | ||
public: | ||
explicit WebUITabStripContainerView(Browser* browser); | ||
|
||
std::unique_ptr<views::View> CreateControlButtons(); | ||
|
||
private: | ||
void ButtonPressed(views::Button* sender, const ui::Event& event) override; | ||
|
||
Browser* const browser_; | ||
views::WebView* const web_view_; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_FRAME_WEBUI_TAB_STRIP_CONTAINER_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters