Commit 2c099c8f authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Share BrowserNonClientFrameView::PaintToolbarBackground

Since the MD update, this was duplicated in 4 places.

The only difference (modulo stylistic differences) was that the ash/mus
versions had an extra line:

  toolbar_bounds.Inset(kClientEdgeThickness, 0);

I determined this was not necessary because the clipping region of the
canvas was already smaller than toolbar_bounds by kClientEdgeThickness.

Bug: none
Change-Id: I4d2dd4bbb844f2108abb606c9f0bc2e2210834f8
Reviewed-on: https://chromium-review.googlesource.com/596813
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491888}
parent 3a211646
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/themes/theme_properties.h" #include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/view_ids.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
...@@ -18,9 +19,11 @@ ...@@ -18,9 +19,11 @@
#include "components/signin/core/common/profile_management_switches.h" #include "components/signin/core/common/profile_management_switches.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/base/theme_provider.h" #include "ui/base/theme_provider.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -166,6 +169,47 @@ void BrowserNonClientFrameView::UpdateProfileIndicatorIcon() { ...@@ -166,6 +169,47 @@ void BrowserNonClientFrameView::UpdateProfileIndicatorIcon() {
profile_indicator_icon_->SetIcon(icon); profile_indicator_icon_->SetIcon(icon);
} }
void BrowserNonClientFrameView::PaintToolbarBackground(
gfx::Canvas* canvas) const {
gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
if (toolbar_bounds.IsEmpty())
return;
gfx::Point toolbar_origin(toolbar_bounds.origin());
ConvertPointToTarget(browser_view(), this, &toolbar_origin);
toolbar_bounds.set_origin(toolbar_origin);
const ui::ThemeProvider* tp = GetThemeProvider();
const int x = toolbar_bounds.x();
const int y = toolbar_bounds.y();
const int w = toolbar_bounds.width();
// Background.
if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) {
canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
x + GetThemeBackgroundXInset(),
y - GetTopInset(false) - GetLayoutInsets(TAB).top(), x,
y, w, toolbar_bounds.height());
} else {
canvas->FillRect(toolbar_bounds,
tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
}
// Top stroke.
gfx::ScopedCanvas scoped_canvas(canvas);
gfx::Rect tabstrip_bounds =
GetMirroredRect(GetBoundsForTabStrip(browser_view()->tabstrip()));
canvas->ClipRect(tabstrip_bounds, SkClipOp::kDifference);
gfx::Rect separator_rect(x, y, w, 0);
separator_rect.set_y(tabstrip_bounds.bottom());
BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(),
separator_rect, true);
// Toolbar/content separator.
BrowserView::Paint1pxHorizontalLine(
canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
toolbar_bounds, true);
}
void BrowserNonClientFrameView::ViewHierarchyChanged( void BrowserNonClientFrameView::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) { const ViewHierarchyChangedDetails& details) {
if (details.is_add && details.child == this) if (details.is_add && details.child == this)
......
...@@ -91,6 +91,8 @@ class BrowserNonClientFrameView : public views::NonClientFrameView, ...@@ -91,6 +91,8 @@ class BrowserNonClientFrameView : public views::NonClientFrameView,
// Updates the icon that indicates incognito/teleportation state. // Updates the icon that indicates incognito/teleportation state.
void UpdateProfileIndicatorIcon(); void UpdateProfileIndicatorIcon();
void PaintToolbarBackground(gfx::Canvas* canvas) const;
const views::View* profile_indicator_icon() const { const views::View* profile_indicator_icon() const {
return profile_indicator_icon_; return profile_indicator_icon_;
} }
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/profiles/profiles_state.h" #include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/layout_constants.h" #include "chrome/browser/ui/layout_constants.h"
...@@ -29,7 +28,6 @@ ...@@ -29,7 +28,6 @@
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/grit/theme_resources.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
...@@ -37,11 +35,8 @@ ...@@ -37,11 +35,8 @@
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/base/theme_provider.h"
#include "ui/compositor/layer_animator.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -431,42 +426,3 @@ bool BrowserNonClientFrameViewAsh::ShouldPaint() const { ...@@ -431,42 +426,3 @@ bool BrowserNonClientFrameViewAsh::ShouldPaint() const {
return immersive_mode_controller->IsEnabled() && return immersive_mode_controller->IsEnabled() &&
immersive_mode_controller->IsRevealed(); immersive_mode_controller->IsRevealed();
} }
void BrowserNonClientFrameViewAsh::PaintToolbarBackground(gfx::Canvas* canvas) {
gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
if (toolbar_bounds.IsEmpty())
return;
gfx::Point toolbar_origin(toolbar_bounds.origin());
View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
toolbar_bounds.set_origin(toolbar_origin);
const ui::ThemeProvider* tp = GetThemeProvider();
// Background.
if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) {
const int bg_y = GetTopInset(false) + GetLayoutInsets(TAB).top();
const int x = toolbar_bounds.x();
const int y = toolbar_bounds.y();
canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
x + GetThemeBackgroundXInset(), y - bg_y, x, y,
toolbar_bounds.width(), toolbar_bounds.height());
} else {
canvas->FillRect(toolbar_bounds,
tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
}
// Top stroke.
gfx::ScopedCanvas scoped_canvas(canvas);
gfx::Rect tabstrip_bounds =
GetMirroredRect(GetBoundsForTabStrip(browser_view()->tabstrip()));
canvas->ClipRect(tabstrip_bounds, SkClipOp::kDifference);
const gfx::Rect separator_rect(toolbar_bounds.x(), tabstrip_bounds.bottom(),
toolbar_bounds.width(), 0);
BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(),
separator_rect, true);
// Toolbar/content separator.
toolbar_bounds.Inset(kClientEdgeThickness, 0);
BrowserView::Paint1pxHorizontalLine(
canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
toolbar_bounds, true);
}
...@@ -103,8 +103,6 @@ class BrowserNonClientFrameViewAsh : public BrowserNonClientFrameView, ...@@ -103,8 +103,6 @@ class BrowserNonClientFrameViewAsh : public BrowserNonClientFrameView,
// need their frames painted. // need their frames painted.
bool ShouldPaint() const; bool ShouldPaint() const;
void PaintToolbarBackground(gfx::Canvas* canvas);
// View which contains the window controls. // View which contains the window controls.
ash::FrameCaptionButtonContainerView* caption_button_container_; ash::FrameCaptionButtonContainerView* caption_button_container_;
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "chrome/browser/ui/views/tab_icon_view.h" #include "chrome/browser/ui/views/tab_icon_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/grit/theme_resources.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
...@@ -29,11 +28,9 @@ ...@@ -29,11 +28,9 @@
#include "ui/base/layout.h" #include "ui/base/layout.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
#include "ui/base/theme_provider.h" #include "ui/base/theme_provider.h"
#include "ui/compositor/layer_animator.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect_conversions.h" #include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/mus/desktop_window_tree_host_mus.h" #include "ui/views/mus/desktop_window_tree_host_mus.h"
#include "ui/views/mus/window_manager_frame_values.h" #include "ui/views/mus/window_manager_frame_values.h"
...@@ -473,46 +470,6 @@ bool BrowserNonClientFrameViewMus::ShouldPaint() const { ...@@ -473,46 +470,6 @@ bool BrowserNonClientFrameViewMus::ShouldPaint() const {
immersive_mode_controller->IsRevealed(); immersive_mode_controller->IsRevealed();
} }
void BrowserNonClientFrameViewMus::PaintToolbarBackground(gfx::Canvas* canvas) {
gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
if (toolbar_bounds.IsEmpty())
return;
gfx::Point toolbar_origin(toolbar_bounds.origin());
View::ConvertPointToTarget(browser_view(), this, &toolbar_origin);
toolbar_bounds.set_origin(toolbar_origin);
const ui::ThemeProvider* tp = GetThemeProvider();
// Background.
if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) {
const int bg_y = GetTopInset(false) + GetLayoutInsets(TAB).top();
const int x = toolbar_bounds.x();
const int y = toolbar_bounds.y();
canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
x + GetThemeBackgroundXInset(), y - bg_y, x, y,
toolbar_bounds.width(), toolbar_bounds.height());
} else {
canvas->FillRect(toolbar_bounds,
tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
}
// Top stroke.
gfx::ScopedCanvas scoped_canvas(canvas);
gfx::Rect tabstrip_bounds =
GetMirroredRect(GetBoundsForTabStrip(browser_view()->tabstrip()));
canvas->ClipRect(tabstrip_bounds, SkClipOp::kDifference);
const gfx::Rect separator_rect(toolbar_bounds.x(), tabstrip_bounds.bottom(),
toolbar_bounds.width(), 0);
BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(),
separator_rect, true);
// Toolbar/content separator.
toolbar_bounds.Inset(kClientEdgeThickness, 0);
BrowserView::Paint1pxHorizontalLine(
canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
toolbar_bounds,
true);
}
void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) { void BrowserNonClientFrameViewMus::PaintContentEdge(gfx::Canvas* canvas) {
DCHECK(!UsePackagedAppHeaderStyle()); DCHECK(!UsePackagedAppHeaderStyle());
const int bottom = frame_values().normal_insets.bottom(); const int bottom = frame_values().normal_insets.bottom();
......
...@@ -93,8 +93,6 @@ class BrowserNonClientFrameViewMus : public BrowserNonClientFrameView, ...@@ -93,8 +93,6 @@ class BrowserNonClientFrameViewMus : public BrowserNonClientFrameView,
// need their frames painted. // need their frames painted.
bool ShouldPaint() const; bool ShouldPaint() const;
void PaintToolbarBackground(gfx::Canvas* canvas);
// Draws the line under the header for windows without a toolbar and not using // Draws the line under the header for windows without a toolbar and not using
// the packaged app header style. // the packaged app header style.
void PaintContentEdge(gfx::Canvas* canvas); void PaintContentEdge(gfx::Canvas* canvas);
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/win/titlebar_config.h" #include "chrome/browser/win/titlebar_config.h"
#include "chrome/grit/theme_resources.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "skia/ext/image_operations.h" #include "skia/ext/image_operations.h"
#include "ui/base/resource/resource_bundle_win.h" #include "ui/base/resource/resource_bundle_win.h"
...@@ -654,48 +653,6 @@ void GlassBrowserFrameView::PaintTitlebar(gfx::Canvas* canvas) const { ...@@ -654,48 +653,6 @@ void GlassBrowserFrameView::PaintTitlebar(gfx::Canvas* canvas) const {
} }
} }
void GlassBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) const {
// TODO(estade): can this be shared with OpaqueBrowserFrameView?
gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
if (toolbar_bounds.IsEmpty())
return;
gfx::Point toolbar_origin(toolbar_bounds.origin());
ConvertPointToTarget(browser_view(), this, &toolbar_origin);
toolbar_bounds.set_origin(toolbar_origin);
const ui::ThemeProvider* tp = GetThemeProvider();
const int x = toolbar_bounds.x();
const int y = toolbar_bounds.y();
const int w = toolbar_bounds.width();
// Background.
if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) {
canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
x + GetThemeBackgroundXInset(),
y - GetTopInset(false) - GetLayoutInsets(TAB).top(), x,
y, w, toolbar_bounds.height());
} else {
canvas->FillRect(toolbar_bounds,
tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
}
// Top stroke.
gfx::Rect separator_rect(x, y, w, 0);
gfx::ScopedCanvas scoped_canvas(canvas);
gfx::Rect tabstrip_bounds =
GetMirroredRect(GetBoundsForTabStrip(browser_view()->tabstrip()));
canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds),
SkClipOp::kDifference);
separator_rect.set_y(tabstrip_bounds.bottom());
BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(),
separator_rect, true);
// Toolbar/content separator.
BrowserView::Paint1pxHorizontalLine(
canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
toolbar_bounds, true);
}
void GlassBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) const { void GlassBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) const {
// Draw the client edge images. // Draw the client edge images.
gfx::Rect client_bounds = CalculateClientAreaBounds(); gfx::Rect client_bounds = CalculateClientAreaBounds();
......
...@@ -136,7 +136,6 @@ class GlassBrowserFrameView : public BrowserNonClientFrameView, ...@@ -136,7 +136,6 @@ class GlassBrowserFrameView : public BrowserNonClientFrameView,
// Paint various sub-components of this view. // Paint various sub-components of this view.
void PaintTitlebar(gfx::Canvas* canvas) const; void PaintTitlebar(gfx::Canvas* canvas) const;
void PaintToolbarBackground(gfx::Canvas* canvas) const;
void PaintClientEdge(gfx::Canvas* canvas) const; void PaintClientEdge(gfx::Canvas* canvas) const;
void FillClientEdgeRects(int x, void FillClientEdgeRects(int x,
int y, int y,
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/resources/grit/views_resources.h" #include "ui/views/resources/grit/views_resources.h"
...@@ -546,48 +545,6 @@ void OpaqueBrowserFrameView::PaintMaximizedFrameBorder( ...@@ -546,48 +545,6 @@ void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(
frame_background_->PaintMaximized(canvas, this); frame_background_->PaintMaximized(canvas, this);
} }
void OpaqueBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) const {
// TODO(estade): can this be shared with OpaqueBrowserFrameView?
gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds());
if (toolbar_bounds.IsEmpty())
return;
gfx::Point toolbar_origin(toolbar_bounds.origin());
ConvertPointToTarget(browser_view(), this, &toolbar_origin);
toolbar_bounds.set_origin(toolbar_origin);
const ui::ThemeProvider* tp = GetThemeProvider();
const int x = toolbar_bounds.x();
const int y = toolbar_bounds.y();
const int w = toolbar_bounds.width();
// Background.
if (tp->HasCustomImage(IDR_THEME_TOOLBAR)) {
canvas->TileImageInt(*tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR),
x + GetThemeBackgroundXInset(),
y - GetTopInset(false) - GetLayoutInsets(TAB).top(), x,
y, w, toolbar_bounds.height());
} else {
canvas->FillRect(toolbar_bounds,
tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
}
// Top stroke.
gfx::Rect separator_rect(x, y, w, 0);
gfx::ScopedCanvas scoped_canvas(canvas);
gfx::Rect tabstrip_bounds =
GetMirroredRect(GetBoundsForTabStrip(browser_view()->tabstrip()));
canvas->sk_canvas()->clipRect(gfx::RectToSkRect(tabstrip_bounds),
SkClipOp::kDifference);
separator_rect.set_y(tabstrip_bounds.bottom());
BrowserView::Paint1pxHorizontalLine(canvas, GetToolbarTopSeparatorColor(),
separator_rect, true);
// Toolbar/content separator.
BrowserView::Paint1pxHorizontalLine(
canvas, tp->GetColor(ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR),
toolbar_bounds, true);
}
void OpaqueBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) const { void OpaqueBrowserFrameView::PaintClientEdge(gfx::Canvas* canvas) const {
const bool tabstrip_visible = browser_view()->IsTabStripVisible(); const bool tabstrip_visible = browser_view()->IsTabStripVisible();
gfx::Rect client_bounds = gfx::Rect client_bounds =
......
...@@ -141,7 +141,6 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView, ...@@ -141,7 +141,6 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
// and titlebar background are a contiguous component. // and titlebar background are a contiguous component.
void PaintRestoredFrameBorder(gfx::Canvas* canvas) const; void PaintRestoredFrameBorder(gfx::Canvas* canvas) const;
void PaintMaximizedFrameBorder(gfx::Canvas* canvas) const; void PaintMaximizedFrameBorder(gfx::Canvas* canvas) const;
void PaintToolbarBackground(gfx::Canvas* canvas) const;
void PaintClientEdge(gfx::Canvas* canvas) const; void PaintClientEdge(gfx::Canvas* canvas) const;
void FillClientEdgeRects(int x, void FillClientEdgeRects(int x,
int y, int y,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment