blob: 93451abb8fd766117927e0596599a606ce80a413 [file] [log] [blame]
// 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 "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.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);
// TODO(crbug.com/1010589) WebContents are initially assumed to be visible by
// default unless explicitly hidden. The WebContents need to be set to hidden
// so that the visibility state of the document in JavaScript is correctly
// initially set to 'hidden', and the 'visibilitychange' events correctly get
// fired.
web_view_->GetWebContents()->WasHidden();
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());
}
views::NativeViewHost* WebUITabStripContainerView::GetNativeViewHost() {
return web_view_->holder();
}
std::unique_ptr<ToolbarButton>
WebUITabStripContainerView::CreateNewTabButton() {
auto new_tab_button = std::make_unique<ToolbarButton>(this);
new_tab_button->SetID(VIEW_ID_WEBUI_TAB_STRIP_NEW_TAB_BUTTON);
new_tab_button->SetTooltipText(
l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB));
return new_tab_button;
}
// TODO(crbug.com/992972): Replace this button with tab counter. Consider
// replacing the "toggle" string with a separate show/hide tooltip string.
std::unique_ptr<ToolbarButton>
WebUITabStripContainerView::CreateToggleButton() {
auto toggle_button = std::make_unique<ToolbarButton>(this);
toggle_button->SetID(VIEW_ID_WEBUI_TAB_STRIP_TOGGLE_BUTTON);
toggle_button->SetTooltipText(
l10n_util::GetStringUTF16(IDS_TOOLTIP_WEBUI_TAB_STRIP_TOGGLE_BUTTON));
return toggle_button;
}
int WebUITabStripContainerView::GetHeightForWidth(int w) const {
constexpr int kWebUITabStripHeightDp = 248;
return kWebUITabStripHeightDp;
}
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();
}
}