-
Notifications
You must be signed in to change notification settings - Fork 862
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from petemill/ui/bookmark-button-relocation
UI: Move bookmark button to primary navigation area
- Loading branch information
Showing
17 changed files
with
634 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
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,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 |
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,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); | ||
} |
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,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 |
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,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); | ||
} |
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,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<views::Widget, views::WidgetObserver> scoped_observer_; | ||
DISALLOW_COPY_AND_ASSIGN(WidgetObserver); | ||
}; | ||
WidgetObserver widget_observer_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BookmarkButton); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_TOOLBAR_BOOKMARK_BUTTON_H_ |
Oops, something went wrong.