From 26ccd70bdde2d7e4c57a91addace66bf25dd3c17 Mon Sep 17 00:00:00 2001 From: Peter Miller Date: Mon, 23 Jul 2018 21:56:22 -0700 Subject: [PATCH] UI: Move bookmark button to primary navigation area Adds a new brave-core Class: `BookmarkButton` (borrows from `StarView`) Adds a new brave-core subclass for `ToolbarView`: `BraveToolbarView`, which creates the BookmarkButton and adds to Layout. Adds a new brave-core subclass for `LocationBar` so that the original `StarView` is no longer displayed. Patches `BookmarkBubbleView` to so it's left side is anchored to the BookmarkButton, since this has moved from the right side to the left side of the ToolbarView. - set_arrow cannot be called in our own method without subclassing BookmarkBubbleView since the original `ShowBubble` method sets the arrow and Inits the bubble before returning. Once it is set it cannot be changed. Note that there is a preference for whether the editing of bookmarks is enabled, though that seems to be automatically controller rather than user-controlled. For example, guest windows will have that setting disabled. --- browser/ui/BUILD.gn | 8 + browser/ui/location_bar/brave_location_bar.cc | 12 + browser/ui/location_bar/brave_location_bar.h | 19 ++ browser/ui/views/frame/brave_browser_view.cc | 13 + browser/ui/views/frame/brave_browser_view.h | 18 ++ browser/ui/views/toolbar/bookmark_button.cc | 97 ++++++++ browser/ui/views/toolbar/bookmark_button.h | 58 +++++ .../ui/views/toolbar/brave_toolbar_view.cc | 234 ++++++++++++++++++ browser/ui/views/toolbar/brave_toolbar_view.h | 37 +++ .../browser/ui/views/frame/browser_view.cc | 6 + .../ui/views/frame/browser_window_factory.cc | 4 + .../views/location_bar/location_bar_view.cc | 6 + ...owser-ui-location_bar-location_bar.h.patch | 13 + ...ws-bookmarks-bookmark_bubble_view.cc.patch | 13 + ...wser-ui-views-toolbar-toolbar_view.h.patch | 54 ++++ .../components/toolbar/vector_icons/star.icon | 25 ++ .../toolbar/vector_icons/star_active.icon | 17 ++ 17 files changed, 634 insertions(+) create mode 100644 browser/ui/location_bar/brave_location_bar.cc create mode 100644 browser/ui/location_bar/brave_location_bar.h create mode 100644 browser/ui/views/frame/brave_browser_view.cc create mode 100644 browser/ui/views/frame/brave_browser_view.h create mode 100644 browser/ui/views/toolbar/bookmark_button.cc create mode 100644 browser/ui/views/toolbar/bookmark_button.h create mode 100644 browser/ui/views/toolbar/brave_toolbar_view.cc create mode 100644 browser/ui/views/toolbar/brave_toolbar_view.h create mode 100644 chromium_src/chrome/browser/ui/views/frame/browser_view.cc create mode 100644 chromium_src/chrome/browser/ui/views/frame/browser_window_factory.cc create mode 100644 chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc create mode 100644 patches/chrome-browser-ui-location_bar-location_bar.h.patch create mode 100644 patches/chrome-browser-ui-views-bookmarks-bookmark_bubble_view.cc.patch create mode 100644 patches/chrome-browser-ui-views-toolbar-toolbar_view.h.patch diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 57e598f6a4e7..4da47e14795a 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -21,10 +21,18 @@ source_set("ui") { "content_settings/brave_widevine_blocked_image_model.h", "content_settings/brave_widevine_content_setting_bubble_model.cc", "content_settings/brave_widevine_content_setting_bubble_model.h", + "location_bar/brave_location_bar.cc", + "location_bar/brave_location_bar.h", "toolbar/brave_app_menu_model.cc", "toolbar/brave_app_menu_model.h", + "views/frame/brave_browser_view.cc", + "views/frame/brave_browser_view.h", "views/importer/brave_import_lock_dialog_view.cc", "views/importer/brave_import_lock_dialog_view.h", + "views/toolbar/bookmark_button.cc", + "views/toolbar/bookmark_button.h", + "views/toolbar/brave_toolbar_view.cc", + "views/toolbar/brave_toolbar_view.h", "webui/basic_ui.cc", "webui/basic_ui.h", "webui/brave_adblock_ui.cc", diff --git a/browser/ui/location_bar/brave_location_bar.cc b/browser/ui/location_bar/brave_location_bar.cc new file mode 100644 index 000000000000..724c55bbd40f --- /dev/null +++ b/browser/ui/location_bar/brave_location_bar.cc @@ -0,0 +1,12 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/location_bar/brave_location_bar.h" + + +// Remove Chromium's original bookmark button, in favor +// of Brave's own bookmark button. +bool BraveLocationBar::IsBookmarkStarHiddenByExtension() const { + return true; +} \ No newline at end of file diff --git a/browser/ui/location_bar/brave_location_bar.h b/browser/ui/location_bar/brave_location_bar.h new file mode 100644 index 000000000000..da7c6ec1a62e --- /dev/null +++ b/browser/ui/location_bar/brave_location_bar.h @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_LOCATION_BAR_BRAVE_LOCATION_BAR_H_ +#define BRAVE_BROWSER_UI_LOCATION_BAR_BRAVE_LOCATION_BAR_H_ + +#include "chrome/browser/ui/location_bar/location_bar.h" + +class BraveLocationBar : public LocationBar { + public: + using LocationBar::LocationBar; + protected: + bool IsBookmarkStarHiddenByExtension() const override; + private: + DISALLOW_COPY_AND_ASSIGN(BraveLocationBar); +}; + +#endif \ No newline at end of file diff --git a/browser/ui/views/frame/brave_browser_view.cc b/browser/ui/views/frame/brave_browser_view.cc new file mode 100644 index 000000000000..3b146c67ebad --- /dev/null +++ b/browser/ui/views/frame/brave_browser_view.cc @@ -0,0 +1,13 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/views/frame/brave_browser_view.h" +#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h" +#include "brave/browser/ui/views/toolbar/bookmark_button.h" + +void BraveBrowserView::SetStarredState(bool is_starred) { + BookmarkButton* button = ((BraveToolbarView *)toolbar())->bookmark_button(); + if (button) + button->SetToggled(is_starred); +} \ No newline at end of file diff --git a/browser/ui/views/frame/brave_browser_view.h b/browser/ui/views/frame/brave_browser_view.h new file mode 100644 index 000000000000..47165cfcee5a --- /dev/null +++ b/browser/ui/views/frame/brave_browser_view.h @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_VIEWS_FRAME_BRAVE_BROWSER_VIEW_H_ +#define BRAVE_BROWSER_UI_VIEWS_FRAME_BRAVE_BROWSER_VIEW_H_ + +#include "chrome/browser/ui/views/frame/browser_view.h" + +class BraveBrowserView : public BrowserView { + public: + using BrowserView::BrowserView; + void SetStarredState(bool is_starred) override; + private: + DISALLOW_COPY_AND_ASSIGN(BraveBrowserView); +}; + +#endif \ No newline at end of file diff --git a/browser/ui/views/toolbar/bookmark_button.cc b/browser/ui/views/toolbar/bookmark_button.cc new file mode 100644 index 000000000000..6d55d37100ef --- /dev/null +++ b/browser/ui/views/toolbar/bookmark_button.cc @@ -0,0 +1,97 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/views/toolbar/bookmark_button.h" + +#include "base/strings/utf_string_conversions.h" +#include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/ui/view_ids.h" +#include "chrome/browser/themes/theme_properties.h" +#include "chrome/grit/generated_resources.h" +#include "components/strings/grit/components_strings.h" +#include "components/toolbar/vector_icons.h" +#include "ui/accessibility/ax_node_data.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/theme_provider.h" +#include "ui/gfx/paint_vector_icon.h" +#include "ui/views/widget/widget.h" + +BookmarkButton::BookmarkButton(views::ButtonListener* listener) + : ToolbarButton(listener), + widget_observer_(this) { + set_id(VIEW_ID_STAR_BUTTON); + set_tag(IDC_BOOKMARK_PAGE); + SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)); + } + +BookmarkButton::~BookmarkButton() { +} + +const char* BookmarkButton::GetClassName() const { + return "BookmarkButton"; +} + +bool BookmarkButton::GetTooltipText(const gfx::Point& p, + base::string16* tooltip) const { + int textId = active_ ? IDS_TOOLTIP_STARRED + : IDS_TOOLTIP_STAR; + tooltip->assign(l10n_util::GetStringUTF16(textId)); + return true; +} + +void BookmarkButton::GetAccessibleNodeData(ui::AXNodeData* node_data) { + int textId = active_ ? IDS_TOOLTIP_STARRED + : IDS_TOOLTIP_STAR; + node_data->role = ax::mojom::Role::kButton; + node_data->SetName(l10n_util::GetStringUTF16(textId)); +} + +void BookmarkButton::SetHighlighted(bool bubble_visible) { + AnimateInkDrop(bubble_visible ? views::InkDropState::ACTIVATED + : views::InkDropState::DEACTIVATED, + nullptr); +} + +void BookmarkButton::SetToggled(bool on) { + + active_ = on; + + const ui::ThemeProvider* tp = GetThemeProvider(); + + SkColor icon_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON); + const gfx::VectorIcon& icon = on + ? toolbar::kStarActiveIcon + : toolbar::kStarIcon; + SetImage(views::Button::STATE_NORMAL, gfx::CreateVectorIcon( + icon, icon_color)); +} + +void BookmarkButton::OnBubbleWidgetCreated(views::Widget* bubble_widget) { + widget_observer_.SetWidget(bubble_widget); + + if (bubble_widget->IsVisible()) + SetHighlighted(true); +} + +BookmarkButton::WidgetObserver::WidgetObserver(BookmarkButton* parent) + : parent_(parent), scoped_observer_(this) {} + +BookmarkButton::WidgetObserver::~WidgetObserver() = default; + +void BookmarkButton::WidgetObserver::SetWidget(views::Widget* widget) { + scoped_observer_.RemoveAll(); + scoped_observer_.Add(widget); +} + +void BookmarkButton::WidgetObserver::OnWidgetDestroying( + views::Widget* widget) { + scoped_observer_.Remove(widget); +} + +void BookmarkButton::WidgetObserver::OnWidgetVisibilityChanged( + views::Widget* widget, + bool visible) { + // |widget| is a bubble that has just got shown / hidden. + parent_->SetHighlighted(visible); +} diff --git a/browser/ui/views/toolbar/bookmark_button.h b/browser/ui/views/toolbar/bookmark_button.h new file mode 100644 index 000000000000..bf06c48f13ab --- /dev/null +++ b/browser/ui/views/toolbar/bookmark_button.h @@ -0,0 +1,58 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_VIEWS_TOOLBAR_BOOKMARK_BUTTON_H_ +#define BRAVE_BROWSER_UI_VIEWS_TOOLBAR_BOOKMARK_BUTTON_H_ + +#include "base/scoped_observer.h" +#include "chrome/browser/ui/views/toolbar/toolbar_button.h" +#include "ui/base/models/simple_menu_model.h" +#include "ui/views/widget/widget_observer.h" + +class BookmarkButton : public ToolbarButton { + public: + BookmarkButton(views::ButtonListener* listener); + ~BookmarkButton() override; + + void SetToggled(bool on); + + // Invoked when a bubble for this icon is created. The Button + // changes highlights based on this widget's visibility. + void OnBubbleWidgetCreated(views::Widget* bubble_widget); + + // ToolbarButton: + bool GetTooltipText(const gfx::Point& p, + base::string16* tooltip) const override; + const char* GetClassName() const override; + void GetAccessibleNodeData(ui::AXNodeData* node_data) override; + + private: + bool active_ = false; + // Highlights the ink drop for the icon, used when the corresponding widget + // is visible. + void SetHighlighted(bool bubble_visible); + + class WidgetObserver : public views::WidgetObserver { + public: + explicit WidgetObserver(BookmarkButton* parent); + ~WidgetObserver() override; + + void SetWidget(views::Widget* widget); + + private: + // views::WidgetObserver: + void OnWidgetDestroying(views::Widget* widget) override; + void OnWidgetVisibilityChanged(views::Widget* widget, + bool visible) override; + + BookmarkButton* const parent_; + ScopedObserver scoped_observer_; + DISALLOW_COPY_AND_ASSIGN(WidgetObserver); + }; + WidgetObserver widget_observer_; + + DISALLOW_COPY_AND_ASSIGN(BookmarkButton); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BOOKMARK_BUTTON_H_ \ No newline at end of file diff --git a/browser/ui/views/toolbar/brave_toolbar_view.cc b/browser/ui/views/toolbar/brave_toolbar_view.cc new file mode 100644 index 000000000000..4d0274504475 --- /dev/null +++ b/browser/ui/views/toolbar/brave_toolbar_view.cc @@ -0,0 +1,234 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h" + +#include "brave/browser/ui/views/toolbar/bookmark_button.h" +#include "chrome/browser/defaults.h" +#include "chrome/browser/ui/views/toolbar/toolbar_view.h" +#include "chrome/browser/extensions/extension_util.h" +#include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" +#include "chrome/browser/ui/layout_constants.h" +#include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" +#include "chrome/browser/ui/views/toolbar/browser_app_menu_button.h" +#include "chrome/browser/ui/views/toolbar/home_button.h" +#include "chrome/browser/ui/views/toolbar/reload_button.h" +#include "chrome/browser/ui/views/toolbar/toolbar_button.h" +#include "components/prefs/pref_service.h" +#include "components/bookmarks/common/bookmark_pref_names.h" +#include "ui/base/material_design/material_design_controller.h" + +namespace { + +int GetToolbarHorizontalPadding() { + // In the touch-optimized UI, we don't use any horizontal paddings; the back + // button starts from the beginning of the view, and the app menu button ends + // at the end of the view. + return ui::MaterialDesignController::IsTouchOptimizedUiEnabled() ? 0 : 8; +} + +} // namespace + +BraveToolbarView::BraveToolbarView(Browser* browser, BrowserView* browser_view) + : ToolbarView(browser, browser_view) { +} + +BraveToolbarView::~BraveToolbarView() {} + +void BraveToolbarView::Init() { + ToolbarView::Init(); + // track changes in bookmarks enabled setting + edit_bookmarks_enabled_.Init( + bookmarks::prefs::kEditBookmarksEnabled, browser()->profile()->GetPrefs(), + base::Bind(&BraveToolbarView::OnEditBookmarksEnabledChanged, + base::Unretained(this))); + + // Only location bar in non-normal mode + if (!is_display_mode_normal()) { + return; + } + + bookmark_ = new BookmarkButton(this); + bookmark_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | ui::EF_MIDDLE_MOUSE_BUTTON); + bookmark_->Init(); + AddChildView(bookmark_); +} + +void BraveToolbarView::OnEditBookmarksEnabledChanged() { + Update(nullptr); +} + +void BraveToolbarView::Update(content::WebContents* tab) { + ToolbarView::Update(tab); + // Decide whether to show the bookmark button + if (bookmark_) { + bookmark_->SetVisible(browser_defaults::bookmarks_enabled && + edit_bookmarks_enabled_.GetValue()); + } +} + +void BraveToolbarView::ShowBookmarkBubble( + const GURL& url, + bool already_bookmarked, + bookmarks::BookmarkBubbleObserver* observer) { + // Show BookmarkBubble attached to Brave's bookmark button + // or the location bar if there is no bookmark button + // (i.e. in non-normal display mode). + views::View* anchor_view = location_bar(); + BookmarkButton* const star_view = bookmark_button(); + if (star_view && star_view->visible()) + anchor_view = star_view; + + std::unique_ptr delegate; + delegate.reset(new BookmarkBubbleSignInDelegate(browser())); + views::Widget* bubble_widget = BookmarkBubbleView::ShowBubble( + anchor_view, gfx::Rect(), nullptr, observer, std::move(delegate), + browser()->profile(), url, already_bookmarked); + if (bubble_widget && star_view) + star_view->OnBubbleWidgetCreated(bubble_widget); +} + +void BraveToolbarView::Layout() { + // If we have not been initialized yet just do nothing. + if (!initialized_) + return; + + if (!is_display_mode_normal()) { + location_bar_->SetBounds(0, 0, width(), + location_bar_->GetPreferredSize().height()); + return; + } + + // We assume all toolbar buttons except for the browser actions are the same + // height. Set toolbar_button_y such that buttons appear vertically centered. + const int toolbar_button_height = + std::min(back_->GetPreferredSize().height(), height()); + const int toolbar_button_y = (height() - toolbar_button_height) / 2; + + // If the window is maximized, we extend the back button to the left so that + // clicking on the left-most pixel will activate the back button. + // TODO(abarth): If the window becomes maximized but is not resized, + // then Layout() might not be called and the back button + // will be slightly the wrong size. We should force a + // Layout() in this case. + // http://crbug.com/5540 + const bool maximized = + browser_->window() && browser_->window()->IsMaximized(); + // The padding at either end of the toolbar. + const int end_padding = GetToolbarHorizontalPadding(); + back_->SetLeadingMargin(maximized ? end_padding : 0); + back_->SetBounds(maximized ? 0 : end_padding, toolbar_button_y, + back_->GetPreferredSize().width(), toolbar_button_height); + const int element_padding = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING); + int next_element_x = back_->bounds().right() + element_padding; + + forward_->SetBounds(next_element_x, toolbar_button_y, + forward_->GetPreferredSize().width(), + toolbar_button_height); + next_element_x = forward_->bounds().right() + element_padding; + + reload_->SetBounds(next_element_x, toolbar_button_y, + reload_->GetPreferredSize().width(), + toolbar_button_height); + next_element_x = reload_->bounds().right(); + + home_->SetSize( + gfx::Size(home_->GetPreferredSize().width(), toolbar_button_height)); + if (show_home_button_.GetValue() || + (browser_->is_app() && extensions::util::IsNewBookmarkAppsEnabled())) { + home_->SetVisible(true); + next_element_x += element_padding; + home_->SetPosition(gfx::Point(next_element_x, toolbar_button_y)); + next_element_x += home_->width(); + } else { + home_->SetVisible(false); + } + + // position Brave's BookmarkButton + if (bookmark_ && bookmark_->visible()) { + next_element_x += element_padding; + bookmark_->SetBounds(next_element_x, toolbar_button_y, bookmark_->GetPreferredSize().width(), toolbar_button_height); + next_element_x = bookmark_->bounds().right(); + } + next_element_x += GetLayoutConstant(TOOLBAR_STANDARD_SPACING); + + int app_menu_width = app_menu_button_->GetPreferredSize().width(); + const int right_padding = GetLayoutConstant(TOOLBAR_STANDARD_SPACING); + + // Note that the browser actions container has its own internal left and right + // padding to visually separate it from the location bar and app menu button. + // However if the container is empty we must account for the |right_padding| + // value used to visually separate the location bar and app menu button. + int available_width = std::max( + 0, + width() - end_padding - app_menu_width - + (browser_actions_->GetPreferredSize().IsEmpty() ? right_padding : 0) - + next_element_x); + if (avatar_) { + available_width -= avatar_->GetPreferredSize().width(); + available_width -= element_padding; + } + // Don't allow the omnibox to shrink to the point of non-existence, so + // subtract its minimum width from the available width to reserve it. + const int browser_actions_width = browser_actions_->GetWidthForMaxWidth( + available_width - location_bar_->GetMinimumSize().width()); + available_width -= browser_actions_width; + const int location_bar_width = available_width; + + const int location_height = location_bar_->GetPreferredSize().height(); + const int location_y = (height() - location_height) / 2; + location_bar_->SetBounds(next_element_x, location_y, + location_bar_width, location_height); + + next_element_x = location_bar_->bounds().right(); + + // Note height() may be zero in fullscreen. + const int browser_actions_height = + std::min(browser_actions_->GetPreferredSize().height(), height()); + const int browser_actions_y = (height() - browser_actions_height) / 2; + browser_actions_->SetBounds(next_element_x, browser_actions_y, + browser_actions_width, browser_actions_height); + next_element_x = browser_actions_->bounds().right(); + if (!browser_actions_width) + next_element_x += right_padding; + + // The browser actions need to do a layout explicitly, because when an + // extension is loaded/unloaded/changed, BrowserActionContainer removes and + // re-adds everything, regardless of whether it has a page action. For a + // page action, browser action bounds do not change, as a result of which + // SetBounds does not do a layout at all. + // TODO(sidchat): Rework the above behavior so that explicit layout is not + // required. + browser_actions_->Layout(); + + if (avatar_) { + avatar_->SetBounds(next_element_x, toolbar_button_y, + avatar_->GetPreferredSize().width(), + toolbar_button_height); + next_element_x = avatar_->bounds().right() + element_padding; + } + + // Extend the app menu to the screen's right edge in maximized mode just like + // we extend the back button to the left edge. + if (maximized) + app_menu_width += end_padding; + + // Set trailing margin before updating the bounds so OnBoundsChange can use + // the trailing margin. + app_menu_button_->SetTrailingMargin(maximized ? end_padding : 0); + app_menu_button_->SetBounds(next_element_x, toolbar_button_y, app_menu_width, + toolbar_button_height); +} + +gfx::Size BraveToolbarView::GetSizeInternal( + gfx::Size (View::*get_size)() const) const { + // Increase the base class width via our added Views + gfx::Size size = ToolbarView::GetSizeInternal(get_size); + if (is_display_mode_normal() && bookmark_ && bookmark_->visible()) { + const int extra_width = GetLayoutConstant(TOOLBAR_ELEMENT_PADDING) + + (bookmark_->*get_size)().width(); + size.Enlarge(extra_width, 0); + } + return size; +} \ No newline at end of file diff --git a/browser/ui/views/toolbar/brave_toolbar_view.h b/browser/ui/views/toolbar/brave_toolbar_view.h new file mode 100644 index 000000000000..8dd18584c258 --- /dev/null +++ b/browser/ui/views/toolbar/brave_toolbar_view.h @@ -0,0 +1,37 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_VIEWS_TOOLBAR_BRAVE_TOOLBAR_VIEW_H_ +#define BRAVE_BROWSER_UI_VIEWS_TOOLBAR_BRAVE_TOOLBAR_VIEW_H_ + +#include "chrome/browser/ui/views/toolbar/toolbar_view.h" +#include "components/prefs/pref_member.h" + +class BookmarkButton; + +class BraveToolbarView : public ToolbarView { + public: + explicit BraveToolbarView(Browser* browser, BrowserView* browser_view); + ~BraveToolbarView() override; + + BookmarkButton* bookmark_button() const { return bookmark_; } + void Init() override; + void Layout() override; + void Update(content::WebContents* tab) override; + void OnEditBookmarksEnabledChanged(); + void ShowBookmarkBubble(const GURL& url, + bool already_bookmarked, + bookmarks::BookmarkBubbleObserver* observer) override; + private: + // Used to avoid duplicating the near-identical logic of + // ToolbarView::CalculatePreferredSize() and ToolbarView::GetMinimumSize(). + // These two functions call through to GetSizeInternal(), passing themselves + // as the function pointer |View::*get_size|. + gfx::Size GetSizeInternal(gfx::Size (View::*get_size)() const) const override; + BookmarkButton* bookmark_ = nullptr; + // Tracks the preference to determine whether bookmark editing is allowed. + BooleanPrefMember edit_bookmarks_enabled_; +}; + +#endif \ No newline at end of file diff --git a/chromium_src/chrome/browser/ui/views/frame/browser_view.cc b/chromium_src/chrome/browser/ui/views/frame/browser_view.cc new file mode 100644 index 000000000000..ea81583cbafb --- /dev/null +++ b/chromium_src/chrome/browser/ui/views/frame/browser_view.cc @@ -0,0 +1,6 @@ +#include "chrome/browser/ui/views/toolbar/toolbar_view.h" +#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h" + +#define ToolbarView BraveToolbarView + +#include "../../../../../../../chrome/browser/ui/views/frame/browser_view.cc" \ No newline at end of file diff --git a/chromium_src/chrome/browser/ui/views/frame/browser_window_factory.cc b/chromium_src/chrome/browser/ui/views/frame/browser_window_factory.cc new file mode 100644 index 000000000000..1dc2a0aea961 --- /dev/null +++ b/chromium_src/chrome/browser/ui/views/frame/browser_window_factory.cc @@ -0,0 +1,4 @@ +#include "chrome/browser/ui/views/frame/browser_view.h" +#include "brave/browser/ui/views/frame/brave_browser_view.h" +#define BrowserView BraveBrowserView +#include "../../../../../../../chrome/browser/ui/views/frame/browser_window_factory.cc" diff --git a/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc new file mode 100644 index 000000000000..9e4c209d9c61 --- /dev/null +++ b/chromium_src/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -0,0 +1,6 @@ +#include "chrome/browser/ui/location_bar/location_bar.h" +#include "brave/browser/ui/location_bar/brave_location_bar.h" + +#define LocationBar BraveLocationBar + +#include "../../../../../../../chrome/browser/ui/views/location_bar/location_bar_view.cc" \ No newline at end of file diff --git a/patches/chrome-browser-ui-location_bar-location_bar.h.patch b/patches/chrome-browser-ui-location_bar-location_bar.h.patch new file mode 100644 index 000000000000..1b2aeb47a83f --- /dev/null +++ b/patches/chrome-browser-ui-location_bar-location_bar.h.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/ui/location_bar/location_bar.h b/chrome/browser/ui/location_bar/location_bar.h +index 411ed06ca4b65943dc6a83c5d0b6633c0eef9a65..2cd80affbd648272ccc567d38025d39a5955e1d1 100644 +--- a/chrome/browser/ui/location_bar/location_bar.h ++++ b/chrome/browser/ui/location_bar/location_bar.h +@@ -81,7 +81,7 @@ class LocationBar { + virtual ~LocationBar(); + + // Checks if any extension has requested that the bookmark star be hidden. +- bool IsBookmarkStarHiddenByExtension() const; ++ virtual bool IsBookmarkStarHiddenByExtension() const; + + private: + class ExtensionLoadObserver; diff --git a/patches/chrome-browser-ui-views-bookmarks-bookmark_bubble_view.cc.patch b/patches/chrome-browser-ui-views-bookmarks-bookmark_bubble_view.cc.patch new file mode 100644 index 000000000000..09aedddc4856 --- /dev/null +++ b/patches/chrome-browser-ui-views-bookmarks-bookmark_bubble_view.cc.patch @@ -0,0 +1,13 @@ +diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +index ccd0049235285c1dc058936b09f2aaae9f25ace1..b6173b3534c58d633a72fc335763fdc887a1dc48 100644 +--- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc ++++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +@@ -70,7 +70,7 @@ views::Widget* BookmarkBubbleView::ShowBubble( + // Bookmark bubble should always anchor TOP_RIGHT, but the + // LocationBarBubbleDelegateView does not know that and may use different + // arrow anchoring. +- bookmark_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT); ++ bookmark_bubble_->set_arrow(views::BubbleBorder::TOP_LEFT); + if (!anchor_view) { + bookmark_bubble_->SetAnchorRect(anchor_rect); + bookmark_bubble_->set_parent_window(parent_window); diff --git a/patches/chrome-browser-ui-views-toolbar-toolbar_view.h.patch b/patches/chrome-browser-ui-views-toolbar-toolbar_view.h.patch new file mode 100644 index 000000000000..e96f998f7626 --- /dev/null +++ b/patches/chrome-browser-ui-views-toolbar-toolbar_view.h.patch @@ -0,0 +1,54 @@ +diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.h b/chrome/browser/ui/views/toolbar/toolbar_view.h +index b9c5bdac43dc2374daf7649b9b4c8c35066227dd..8d1d9585374e0220ecd99674a1703b62aecc3b14 100644 +--- a/chrome/browser/ui/views/toolbar/toolbar_view.h ++++ b/chrome/browser/ui/views/toolbar/toolbar_view.h +@@ -42,6 +42,7 @@ class Browser; + class HomeButton; + class ReloadButton; + class ToolbarButton; ++class BraveToolbarView; + + namespace bookmarks { + class BookmarkBubbleObserver; +@@ -59,6 +60,7 @@ class ToolbarView : public views::AccessiblePaneView, + public UpgradeObserver, + public ToolbarButtonProvider, + public BrowserRootView::DropTarget { ++ friend class BraveToolbarView; + public: + // The view class name. + static const char kViewClassName[]; +@@ -67,13 +69,13 @@ class ToolbarView : public views::AccessiblePaneView, + ~ToolbarView() override; + + // Create the contents of the Browser Toolbar. +- void Init(); ++ virtual void Init(); + + // Forces the toolbar (and transitively the location bar) to update its + // current state. If |tab| is non-NULL, we're switching (back?) to this tab + // and should restore any previous location bar state (such as user editing) + // as well. +- void Update(content::WebContents* tab); ++ virtual void Update(content::WebContents* tab); + + // Clears the current state for |tab|. + void ResetTabState(content::WebContents* tab); +@@ -94,7 +96,7 @@ class ToolbarView : public views::AccessiblePaneView, + #endif // defined(OS_CHROMEOS) + + // Shows a bookmark bubble and anchors it appropriately. +- void ShowBookmarkBubble(const GURL& url, ++ virtual void ShowBookmarkBubble(const GURL& url, + bool already_bookmarked, + bookmarks::BookmarkBubbleObserver* observer); + +@@ -204,7 +206,7 @@ class ToolbarView : public views::AccessiblePaneView, + // ToolbarView::CalculatePreferredSize() and ToolbarView::GetMinimumSize(). + // These two functions call through to GetSizeInternal(), passing themselves + // as the function pointer |View::*get_size|. +- gfx::Size GetSizeInternal(gfx::Size (View::*get_size)() const) const; ++ virtual gfx::Size GetSizeInternal(gfx::Size (View::*get_size)() const) const; + + // Given toolbar contents of size |size|, returns the total toolbar size. + gfx::Size SizeForContentSize(gfx::Size size) const; diff --git a/vector_icons/components/toolbar/vector_icons/star.icon b/vector_icons/components/toolbar/vector_icons/star.icon index 924793b2c70c..4c645ea78356 100644 --- a/vector_icons/components/toolbar/vector_icons/star.icon +++ b/vector_icons/components/toolbar/vector_icons/star.icon @@ -26,3 +26,28 @@ R_LINE_TO, -6.65f, -3.88f, R_LINE_TO, -6.65f, 3.88f, R_ARC_TO, 2.56f, 2.56f, 0, 0, 1, -1.29f, 0.35f, CLOSE + +CANVAS_DIMENSIONS, 16, +MOVE_TO, 8.25f, 11.62f, +R_CUBIC_TO, 0.25f, 0, 0.49f, 0.06f, 0.71f, 0.19f, +LINE_TO, 12, 13.59f, +V_LINE_TO, 2.5f, +H_LINE_TO, 4.5f, +R_V_LINE_TO, 11.09f, +R_LINE_TO, 3.04f, -1.77f, +R_CUBIC_TO, 0.22f, -0.13f, 0.46f, -0.19f, 0.71f, -0.19f, +CLOSE, +R_MOVE_TO, -3.97f, 3.63f, +R_CUBIC_TO, -0.22f, 0, -0.44f, -0.06f, -0.64f, -0.17f, +CUBIC_TO, 3.24f, 14.85f, 3, 14.43f, 3, 13.97f, +V_LINE_TO, 2.28f, +CUBIC_TO, 3, 1.57f, 3.57f, 1, 4.28f, 1, +R_H_LINE_TO, 7.94f, +CUBIC_TO, 12.93f, 1, 13.5f, 1.57f, 13.5f, 2.28f, +R_V_LINE_TO, 11.69f, +R_CUBIC_TO, 0, 0.46f, -0.24f, 0.88f, -0.64f, 1.11f, +R_CUBIC_TO, -0.4f, 0.23f, -0.89f, 0.22f, -1.28f, 0, +R_LINE_TO, -3.32f, -1.94f, +R_LINE_TO, -3.32f, 1.94f, +R_CUBIC_TO, -0.2f, 0.12f, -0.42f, 0.17f, -0.65f, 0.17f, +CLOSE \ No newline at end of file diff --git a/vector_icons/components/toolbar/vector_icons/star_active.icon b/vector_icons/components/toolbar/vector_icons/star_active.icon index 1fd6c97800e9..8b75d7860725 100644 --- a/vector_icons/components/toolbar/vector_icons/star_active.icon +++ b/vector_icons/components/toolbar/vector_icons/star_active.icon @@ -17,3 +17,20 @@ R_LINE_TO, -6.65f, -3.88f, R_LINE_TO, -6.65f, 3.88f, R_ARC_TO, 2.56f, 2.56f, 0, 0, 1, -1.29f, 0.35f, CLOSE + + +CANVAS_DIMENSIONS, 16, +MOVE_TO, 4.28f, 15.25f, +R_CUBIC_TO, -0.22f, 0, -0.44f, -0.06f, -0.64f, -0.17f, +CUBIC_TO, 3.24f, 14.85f, 3, 14.43f, 3, 13.97f, +V_LINE_TO, 2.28f, +CUBIC_TO, 3, 1.57f, 3.57f, 1, 4.28f, 1, +R_H_LINE_TO, 7.94f, +CUBIC_TO, 12.93f, 1, 13.5f, 1.57f, 13.5f, 2.28f, +R_V_LINE_TO, 11.69f, +R_CUBIC_TO, 0, 0.46f, -0.24f, 0.88f, -0.64f, 1.11f, +R_CUBIC_TO, -0.4f, 0.23f, -0.89f, 0.22f, -1.28f, 0, +R_LINE_TO, -3.32f, -1.94f, +R_LINE_TO, -3.32f, 1.94f, +R_CUBIC_TO, -0.2f, 0.12f, -0.42f, 0.17f, -0.65f, 0.17f, +CLOSE \ No newline at end of file