Skip to content

Commit

Permalink
Merge pull request #280 from petemill/ui/bookmark-button-relocation
Browse files Browse the repository at this point in the history
UI: Move bookmark button to primary navigation area
  • Loading branch information
bbondy committed Aug 18, 2018
2 parents 4d79b46 + 26ccd70 commit 1e10d6d
Show file tree
Hide file tree
Showing 17 changed files with 634 additions and 0 deletions.
8 changes: 8 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions browser/ui/location_bar/brave_location_bar.cc
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;
}
19 changes: 19 additions & 0 deletions browser/ui/location_bar/brave_location_bar.h
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
13 changes: 13 additions & 0 deletions browser/ui/views/frame/brave_browser_view.cc
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);
}
18 changes: 18 additions & 0 deletions browser/ui/views/frame/brave_browser_view.h
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
97 changes: 97 additions & 0 deletions browser/ui/views/toolbar/bookmark_button.cc
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);
}
58 changes: 58 additions & 0 deletions browser/ui/views/toolbar/bookmark_button.h
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_
Loading

0 comments on commit 1e10d6d

Please sign in to comment.