-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Brave Actions are sized at 18px and highlighted correctly
- Loading branch information
Showing
9 changed files
with
261 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* 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/. */ | ||
|
||
namespace brave_actions { | ||
|
||
const int kBraveActionGraphicSize = 18; | ||
const int kBraveActionRightMargin = 2; | ||
|
||
} |
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,36 @@ | ||
/* 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/brave_actions/brave_action_view.h" | ||
|
||
#include "brave/browser/ui/brave_actions/constants.h" | ||
#include "chrome/browser/themes/theme_properties.h" | ||
#include "chrome/browser/ui/layout_constants.h" | ||
#include "chrome/browser/ui/views/chrome_layout_provider.h" | ||
#include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | ||
#include "chrome/browser/ui/views/toolbar/toolbar_ink_drop_util.h" | ||
#include "third_party/skia/include/core/SkPath.h" | ||
#include "ui/gfx/geometry/insets.h" | ||
#include "ui/gfx/geometry/rect.h" | ||
#include "ui/gfx/geometry/size.h" | ||
#include "ui/views/controls/button/menu_button.h" | ||
#include "ui/views/view.h" | ||
#include "ui/views/view_properties.h" | ||
|
||
void BraveActionView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | ||
// Set the highlight path for the toolbar button, | ||
// making it inset so that the badge can show outside it in the | ||
// fake margin on the right that we are creating. | ||
gfx::Insets highlight_insets(0, 0, 0, brave_actions::kBraveActionRightMargin); | ||
gfx::Rect rect(size()); | ||
rect.Inset(highlight_insets); | ||
const int radii = ChromeLayoutProvider::Get()->GetCornerRadiusMetric( | ||
views::EMPHASIS_MAXIMUM, rect.size()); | ||
|
||
auto path = std::make_unique<SkPath>(); | ||
path->addRoundRect(gfx::RectToSkRect(rect), radii, radii); | ||
SetProperty(views::kHighlightPathKey, path.release()); | ||
|
||
MenuButton::OnBoundsChanged(previous_bounds); | ||
} |
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,24 @@ | ||
/* 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_BRAVE_ACTIONS_BRAVE_ACTION_VIEW_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_BRAVE_ACTIONS_BRAVE_ACTION_VIEW_H_ | ||
|
||
#include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | ||
|
||
namespace gfx { | ||
class Rect; | ||
} | ||
|
||
// Subclasses ToolbarActionViewc so that the notification badge can be painted | ||
// outside the highlight bubble. | ||
class BraveActionView : public ToolbarActionView { | ||
public: | ||
using ToolbarActionView::ToolbarActionView; | ||
// views::MenuButton: | ||
void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | ||
DISALLOW_COPY_AND_ASSIGN(BraveActionView); | ||
}; | ||
|
||
#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
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,73 @@ | ||
/* 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/rounded_separator.h" | ||
|
||
#include "ui/accessibility/ax_node_data.h" | ||
#include "ui/gfx/canvas.h" | ||
#include "ui/native_theme/native_theme.h" | ||
|
||
// static | ||
const char RoundedSeparator::kViewClassName[] = "RoundedSeparator"; | ||
|
||
// static | ||
const int RoundedSeparator::kThickness = 1; | ||
|
||
RoundedSeparator::RoundedSeparator() {} | ||
|
||
RoundedSeparator::~RoundedSeparator() {} | ||
|
||
void RoundedSeparator::SetColor(SkColor color) { | ||
overridden_color_ = color; | ||
SchedulePaint(); | ||
} | ||
|
||
void RoundedSeparator::SetPreferredHeight(int height) { | ||
preferred_height_ = height; | ||
PreferredSizeChanged(); | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Separator, View overrides: | ||
|
||
gfx::Size RoundedSeparator::CalculatePreferredSize() const { | ||
gfx::Size size(kThickness, preferred_height_); | ||
gfx::Insets insets = GetInsets(); | ||
size.Enlarge(insets.width(), insets.height()); | ||
return size; | ||
} | ||
|
||
void RoundedSeparator::GetAccessibleNodeData(ui::AXNodeData* node_data) { | ||
node_data->role = ax::mojom::Role::kSplitter; | ||
} | ||
|
||
void RoundedSeparator::OnPaint(gfx::Canvas* canvas) { | ||
SkColor color = overridden_color_ | ||
? *overridden_color_ | ||
: GetNativeTheme()->GetSystemColor( | ||
ui::NativeTheme::kColorId_SeparatorColor); | ||
|
||
float dsf = canvas->UndoDeviceScaleFactor(); | ||
|
||
// The separator fills its bounds, but avoid filling partial pixels. | ||
gfx::Rect aligned = gfx::ScaleToEnclosedRect(GetContentsBounds(), dsf, dsf); | ||
|
||
|
||
// At least 1 pixel should be drawn to make the separator visible. | ||
aligned.set_width(std::max(1, aligned.width())); | ||
aligned.set_height(std::max(1, aligned.height())); | ||
|
||
const int separator_radius = aligned.width() / 2; | ||
|
||
cc::PaintFlags flags; | ||
flags.setAntiAlias(true); | ||
flags.setColor(color); | ||
canvas->DrawRoundRect(aligned, separator_radius, flags); | ||
|
||
View::OnPaint(canvas); | ||
} | ||
|
||
const char* RoundedSeparator::GetClassName() const { | ||
return kViewClassName; | ||
} |
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,44 @@ | ||
/* 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_ROUNDED_SEPARATOR_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_ROUNDED_SEPARATOR_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/macros.h" | ||
#include "base/optional.h" | ||
#include "ui/views/view.h" | ||
|
||
// The RoundedSeparator class is a view that shows a line used to visually separate | ||
// other views. | ||
class RoundedSeparator : public views::View { | ||
public: | ||
// The separator's class name. | ||
static const char kViewClassName[]; | ||
|
||
// The separator's thickness in dip. | ||
static const int kThickness; | ||
|
||
RoundedSeparator(); | ||
~RoundedSeparator() override; | ||
|
||
void SetColor(SkColor color); | ||
|
||
void SetPreferredHeight(int height); | ||
|
||
// Overridden from View: | ||
gfx::Size CalculatePreferredSize() const override; | ||
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | ||
void OnPaint(gfx::Canvas* canvas) override; | ||
const char* GetClassName() const override; | ||
|
||
private: | ||
int preferred_height_ = kThickness; | ||
base::Optional<SkColor> overridden_color_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(RoundedSeparator); | ||
}; | ||
|
||
#endif |