Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1115)

Unified Diff: chrome/browser/ui/views/frame/browser_frame_view_mac.mm

Issue 664703003: Stash: hacks to get MacViews chrome browser window working (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/frame/browser_frame_view_mac.mm
diff --git a/chrome/browser/ui/views/frame/browser_frame_view_mac.mm b/chrome/browser/ui/views/frame/browser_frame_view_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..e51fd7e368505b2e72ee6998236a48dd0f5006d3
--- /dev/null
+++ b/chrome/browser/ui/views/frame/browser_frame_view_mac.mm
@@ -0,0 +1,213 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/frame/browser_frame_view_mac.h"
+
+#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/ui/views/frame/browser_frame.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/browser/ui/views/tabs/tab_strip.h"
+#include "grit/theme_resources.h"
+#include "ui/base/theme_provider.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/widget/widget_delegate.h"
+
+namespace {
+
+// The content left/right images have a shadow built into them.
+const int kContentEdgeShadowThickness = 2;
+
+} // namespace
+
+///////////////////////////////////////////////////////////////////////////////
+// BrowserFrameViewMac, public:
+
+BrowserFrameViewMac::BrowserFrameViewMac(BrowserFrame* frame,
+ BrowserView* browser_view)
+ : BrowserNonClientFrameView(frame, browser_view) {
+}
+
+BrowserFrameViewMac::~BrowserFrameViewMac() {
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// BrowserFrameViewMac, BrowserNonClientFrameView implementation:
+
+gfx::Rect BrowserFrameViewMac::GetBoundsForTabStrip(
+ views::View* tabstrip) const {
+ return gfx::Rect(0, 0, width(), tabstrip->GetPreferredSize().height());
+}
+
+int BrowserFrameViewMac::GetTopInset() const {
+ return 0;
+}
+
+int BrowserFrameViewMac::GetThemeBackgroundXInset() const {
+ return 0;
+}
+
+void BrowserFrameViewMac::UpdateThrobber(bool running) {
+}
+
+gfx::Size BrowserFrameViewMac::GetMinimumSize() const {
+ return frame()->client_view()->GetMinimumSize();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// BrowserFrameViewMac, NonClientFrameView overrides:
+
+gfx::Rect BrowserFrameViewMac::GetBoundsForClientView() const {
+ // return bounds();
+ // TODO(andresantoso): Tab strip and toolbar won't draw without this -1?
+ return gfx::Rect(0, 0, width()-1, height());
+}
+
+gfx::Rect BrowserFrameViewMac::GetWindowBoundsForClientBounds(
+ const gfx::Rect& client_bounds) const {
+ return client_bounds;
+}
+
+int BrowserFrameViewMac::NonClientHitTest(const gfx::Point& point) {
+ return frame()->client_view()->NonClientHitTest(point);
+}
+
+void BrowserFrameViewMac::GetWindowMask(const gfx::Size& size,
+ gfx::Path* window_mask) {
+ // Nothing to do.
+}
+
+void BrowserFrameViewMac::ResetWindowControls() {
+ // Nothing to do.
+}
+
+void BrowserFrameViewMac::UpdateWindowIcon() {
+ // Nothing to do.
+}
+
+void BrowserFrameViewMac::UpdateWindowTitle() {
+ // Nothing to do.
+}
+
+void BrowserFrameViewMac::SizeConstraintsChanged() {
+ // Nothing to do.
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// BrowserFrameViewMac, views::View overrides:
+
+void BrowserFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) {
+ 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);
+
+ int x = toolbar_bounds.x();
+ int w = toolbar_bounds.width();
+ int y = toolbar_bounds.y();
+ int h = toolbar_bounds.height();
+
+ // Gross hack: We split the toolbar images into two pieces, since sometimes
+ // (popup mode) the toolbar isn't tall enough to show the whole image. The
+ // split happens between the top shadow section and the bottom gradient
+ // section so that we never break the gradient.
+ int split_point = kFrameShadowThickness * 2;
+ int bottom_y = y + split_point;
+ ui::ThemeProvider* tp = GetThemeProvider();
+ gfx::ImageSkia* toolbar_left = tp->GetImageSkiaNamed(
+ IDR_CONTENT_TOP_LEFT_CORNER);
+ int bottom_edge_height = std::min(toolbar_left->height(), h) - split_point;
+
+ // Split our canvas out so we can mask out the corners of the toolbar
+ // without masking out the frame.
+ canvas->SaveLayerAlpha(
+ 255, gfx::Rect(x - kClientEdgeThickness, y, w + kClientEdgeThickness * 3,
+ h));
+
+ // Paint the bottom rect.
+ canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height),
+ tp->GetColor(ThemeProperties::COLOR_TOOLBAR));
+
+ // Tile the toolbar image starting at the frame edge on the left and where the
+ // horizontal tabstrip is (or would be) on the top.
+ gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR);
+ canvas->TileImageInt(*theme_toolbar,
+ x + GetThemeBackgroundXInset(),
+ bottom_y - GetTopInset(),
+ x, bottom_y, w, theme_toolbar->height());
+
+ // Draw rounded corners for the tab.
+ gfx::ImageSkia* toolbar_left_mask =
+ tp->GetImageSkiaNamed(IDR_CONTENT_TOP_LEFT_CORNER_MASK);
+ gfx::ImageSkia* toolbar_right_mask =
+ tp->GetImageSkiaNamed(IDR_CONTENT_TOP_RIGHT_CORNER_MASK);
+
+ // We mask out the corners by using the DestinationIn transfer mode,
+ // which keeps the RGB pixels from the destination and the alpha from
+ // the source.
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
+
+ // Mask the left edge.
+ int left_x = x - kContentEdgeShadowThickness;
+ canvas->DrawImageInt(*toolbar_left_mask, 0, 0, toolbar_left_mask->width(),
+ split_point, left_x, y, toolbar_left_mask->width(),
+ split_point, false, paint);
+ canvas->DrawImageInt(*toolbar_left_mask, 0,
+ toolbar_left_mask->height() - bottom_edge_height,
+ toolbar_left_mask->width(), bottom_edge_height, left_x, bottom_y,
+ toolbar_left_mask->width(), bottom_edge_height, false, paint);
+
+ // Mask the right edge.
+ int right_x =
+ x + w - toolbar_right_mask->width() + kContentEdgeShadowThickness;
+ canvas->DrawImageInt(*toolbar_right_mask, 0, 0, toolbar_right_mask->width(),
+ split_point, right_x, y, toolbar_right_mask->width(),
+ split_point, false, paint);
+ canvas->DrawImageInt(*toolbar_right_mask, 0,
+ toolbar_right_mask->height() - bottom_edge_height,
+ toolbar_right_mask->width(), bottom_edge_height, right_x, bottom_y,
+ toolbar_right_mask->width(), bottom_edge_height, false, paint);
+ canvas->Restore();
+
+ canvas->DrawImageInt(*toolbar_left, 0, 0, toolbar_left->width(), split_point,
+ left_x, y, toolbar_left->width(), split_point, false);
+ canvas->DrawImageInt(*toolbar_left, 0,
+ toolbar_left->height() - bottom_edge_height, toolbar_left->width(),
+ bottom_edge_height, left_x, bottom_y, toolbar_left->width(),
+ bottom_edge_height, false);
+
+ gfx::ImageSkia* toolbar_center =
+ tp->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER);
+ canvas->TileImageInt(*toolbar_center, 0, 0, left_x + toolbar_left->width(),
+ y, right_x - (left_x + toolbar_left->width()),
+ split_point);
+
+ gfx::ImageSkia* toolbar_right = tp->GetImageSkiaNamed(
+ IDR_CONTENT_TOP_RIGHT_CORNER);
+ canvas->DrawImageInt(*toolbar_right, 0, 0, toolbar_right->width(),
+ split_point, right_x, y, toolbar_right->width(), split_point, false);
+ canvas->DrawImageInt(*toolbar_right, 0,
+ toolbar_right->height() - bottom_edge_height, toolbar_right->width(),
+ bottom_edge_height, right_x, bottom_y, toolbar_right->width(),
+ bottom_edge_height, false);
+
+ // Draw the content/toolbar separator.
+ canvas->FillRect(
+ gfx::Rect(x + kClientEdgeThickness,
+ toolbar_bounds.bottom() - kClientEdgeThickness,
+ w - (2 * kClientEdgeThickness),
+ kClientEdgeThickness),
+ ThemeProperties::GetDefaultColor(
+ ThemeProperties::COLOR_TOOLBAR_SEPARATOR));
+}
+
+void BrowserFrameViewMac::OnPaint(gfx::Canvas* canvas) {
+ // canvas->DrawColor(GetThemeProvider()->GetColor(ThemeProperties::COLOR_FRAME));
+ gfx::ImageSkia* image = GetThemeProvider()->GetImageSkiaNamed(IDR_THEME_FRAME);
+ canvas->TileImageInt(*image, 0, 0, width(), image->height());
+
+ PaintToolbarBackground(canvas);
+}

Powered by Google App Engine
This is Rietveld 408576698