| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_mac.h" |
| 6 | 6 |
| 7 #include "chrome/browser/themes/theme_properties.h" | 7 #include "chrome/browser/themes/theme_properties.h" |
| 8 #include "chrome/browser/ui/layout_constants.h" | 8 #include "chrome/browser/ui/layout_constants.h" |
| 9 #include "chrome/browser/ui/views/frame/browser_frame.h" | 9 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 10 #include "chrome/browser/ui/views/frame/browser_view.h" | 10 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view_layout.h" | 11 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
| 12 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
| 12 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 13 #include "ui/base/hit_test.h" | 14 #include "ui/base/hit_test.h" |
| 14 #include "ui/base/theme_provider.h" | 15 #include "ui/base/theme_provider.h" |
| 15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 // How far to inset the tabstrip from the sides of the window. | 20 // How far to inset the tabstrip from the sides of the window. |
| 20 const int kTabstripTopInset = 8; | 21 const int kTabstripTopInset = 8; |
| 21 const int kTabstripLeftInset = 70; // Make room for window control buttons. | 22 const int kTabstripLeftInset = 70; // Make room for window control buttons. |
| 22 const int kTabstripRightInset = 0; | 23 |
| 24 // Padding on each side of either the incognito icon, or the profile switcher. |
| 25 const int kAvatarButtonPadding = 3; |
| 23 | 26 |
| 24 } // namespace | 27 } // namespace |
| 25 | 28 |
| 26 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
| 27 // BrowserNonClientFrameViewMac, public: | 30 // BrowserNonClientFrameViewMac, public: |
| 28 | 31 |
| 29 BrowserNonClientFrameViewMac::BrowserNonClientFrameViewMac( | 32 BrowserNonClientFrameViewMac::BrowserNonClientFrameViewMac( |
| 30 BrowserFrame* frame, BrowserView* browser_view) | 33 BrowserFrame* frame, |
| 31 : BrowserNonClientFrameView(frame, browser_view) { | 34 BrowserView* browser_view) |
| 32 } | 35 : BrowserNonClientFrameView(frame, browser_view), profile_switcher_(this) {} |
| 33 | 36 |
| 34 BrowserNonClientFrameViewMac::~BrowserNonClientFrameViewMac() { | 37 BrowserNonClientFrameViewMac::~BrowserNonClientFrameViewMac() { |
| 35 } | 38 } |
| 36 | 39 |
| 37 /////////////////////////////////////////////////////////////////////////////// | 40 /////////////////////////////////////////////////////////////////////////////// |
| 38 // BrowserNonClientFrameViewMac, BrowserNonClientFrameView implementation: | 41 // BrowserNonClientFrameViewMac, BrowserNonClientFrameView implementation: |
| 39 | 42 |
| 43 void BrowserNonClientFrameViewMac::OnBrowserViewInitViewsComplete() { |
| 44 // Update avatars here rather than the constructor to avoid triggering a call |
| 45 // to Widget::OnRootViewLayout() before the NonClientView is initialized. |
| 46 UpdateProfileIcons(); |
| 47 } |
| 48 |
| 40 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForTabStrip( | 49 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForTabStrip( |
| 41 views::View* tabstrip) const { | 50 views::View* tabstrip) const { |
| 42 DCHECK(tabstrip); | 51 DCHECK(tabstrip); |
| 43 gfx::Rect bounds = gfx::Rect(0, kTabstripTopInset, | 52 gfx::Rect bounds(0, kTabstripTopInset, width(), |
| 44 width(), tabstrip->GetPreferredSize().height()); | 53 tabstrip->GetPreferredSize().height()); |
| 45 bounds.Inset(kTabstripLeftInset, 0, kTabstripRightInset, 0); | 54 bounds.Inset(kTabstripLeftInset, 0, GetTabStripRightInset(), 0); |
| 46 return bounds; | 55 return bounds; |
| 47 } | 56 } |
| 48 | 57 |
| 49 int BrowserNonClientFrameViewMac::GetTopInset(bool restored) const { | 58 int BrowserNonClientFrameViewMac::GetTopInset(bool restored) const { |
| 50 return browser_view()->IsTabStripVisible() ? kTabstripTopInset : 0; | 59 return browser_view()->IsTabStripVisible() ? kTabstripTopInset : 0; |
| 51 } | 60 } |
| 52 | 61 |
| 53 int BrowserNonClientFrameViewMac::GetThemeBackgroundXInset() const { | 62 int BrowserNonClientFrameViewMac::GetThemeBackgroundXInset() const { |
| 54 return 0; | 63 return 0; |
| 55 } | 64 } |
| 56 | 65 |
| 57 void BrowserNonClientFrameViewMac::UpdateThrobber(bool running) { | 66 void BrowserNonClientFrameViewMac::UpdateThrobber(bool running) { |
| 58 } | 67 } |
| 59 | 68 |
| 69 views::View* BrowserNonClientFrameViewMac::GetProfileSwitcherView() const { |
| 70 return profile_switcher_.view(); |
| 71 } |
| 72 |
| 60 /////////////////////////////////////////////////////////////////////////////// | 73 /////////////////////////////////////////////////////////////////////////////// |
| 61 // BrowserNonClientFrameViewMac, views::NonClientFrameView implementation: | 74 // BrowserNonClientFrameViewMac, views::NonClientFrameView implementation: |
| 62 | 75 |
| 63 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForClientView() const { | 76 gfx::Rect BrowserNonClientFrameViewMac::GetBoundsForClientView() const { |
| 64 return bounds(); | 77 return bounds(); |
| 65 } | 78 } |
| 66 | 79 |
| 67 gfx::Rect BrowserNonClientFrameViewMac::GetWindowBoundsForClientBounds( | 80 gfx::Rect BrowserNonClientFrameViewMac::GetWindowBoundsForClientBounds( |
| 68 const gfx::Rect& client_bounds) const { | 81 const gfx::Rect& client_bounds) const { |
| 69 return client_bounds; | 82 return client_bounds; |
| 70 } | 83 } |
| 71 | 84 |
| 72 int BrowserNonClientFrameViewMac::NonClientHitTest(const gfx::Point& point) { | 85 int BrowserNonClientFrameViewMac::NonClientHitTest(const gfx::Point& point) { |
| 86 if (profile_switcher_.HitTest(point)) |
| 87 return HTCLIENT; |
| 88 |
| 73 int component = frame()->client_view()->NonClientHitTest(point); | 89 int component = frame()->client_view()->NonClientHitTest(point); |
| 74 | 90 |
| 75 // BrowserView::NonClientHitTest will return HTNOWHERE for points that hit | 91 // BrowserView::NonClientHitTest will return HTNOWHERE for points that hit |
| 76 // the native title bar. On Mac, we need to explicitly return HTCAPTION for | 92 // the native title bar. On Mac, we need to explicitly return HTCAPTION for |
| 77 // those points. | 93 // those points. |
| 78 if (component == HTNOWHERE && bounds().Contains(point)) | 94 if (component == HTNOWHERE && bounds().Contains(point)) |
| 79 return HTCAPTION; | 95 return HTCAPTION; |
| 80 | 96 |
| 81 return component; | 97 return component; |
| 82 } | 98 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 130 |
| 115 canvas->DrawColor(GetFrameColor()); | 131 canvas->DrawColor(GetFrameColor()); |
| 116 | 132 |
| 117 if (!GetThemeProvider()->UsingSystemTheme()) | 133 if (!GetThemeProvider()->UsingSystemTheme()) |
| 118 PaintThemedFrame(canvas); | 134 PaintThemedFrame(canvas); |
| 119 | 135 |
| 120 if (browser_view()->IsToolbarVisible()) | 136 if (browser_view()->IsToolbarVisible()) |
| 121 PaintToolbarBackground(canvas); | 137 PaintToolbarBackground(canvas); |
| 122 } | 138 } |
| 123 | 139 |
| 140 void BrowserNonClientFrameViewMac::Layout() { |
| 141 views::View* switcher_button = profile_switcher_.view(); |
| 142 if (switcher_button) { |
| 143 const gfx::Size button_size = switcher_button->GetPreferredSize(); |
| 144 switcher_button->SetBounds( |
| 145 width() - GetTabStripRightInset() + kAvatarButtonPadding, |
| 146 kAvatarButtonPadding, button_size.width(), button_size.height()); |
| 147 } |
| 148 if (profile_indicator_icon()) { |
| 149 DCHECK(!switcher_button); |
| 150 const gfx::Size button_size = GetOTRAvatarIcon().size(); |
| 151 |
| 152 // The incognito icon needs to hug the base of the tab strip. |
| 153 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); |
| 154 const int bottom = GetTopInset(false) + |
| 155 browser_view()->GetTabStripHeight() - insets.bottom(); |
| 156 |
| 157 profile_indicator_icon()->SetBounds( |
| 158 width() - GetTabStripRightInset() + kAvatarButtonPadding, |
| 159 bottom - button_size.height(), button_size.width(), |
| 160 button_size.height()); |
| 161 } |
| 162 } |
| 163 |
| 164 bool BrowserNonClientFrameViewMac::DoesIntersectRect( |
| 165 const View* target, |
| 166 const gfx::Rect& rect) const { |
| 167 DCHECK_EQ(target, this); |
| 168 // Note this doesn't check the incognito icon, since that is non-interactive. |
| 169 return profile_switcher_.Intersects(rect) || |
| 170 NonClientFrameView::DoesIntersectRect(target, rect); |
| 171 } |
| 172 |
| 124 // BrowserNonClientFrameView: | 173 // BrowserNonClientFrameView: |
| 125 void BrowserNonClientFrameViewMac::UpdateProfileIcons() { | 174 void BrowserNonClientFrameViewMac::UpdateProfileIcons() { |
| 126 NOTIMPLEMENTED(); | 175 if (browser_view()->IsRegularOrGuestSession()) |
| 176 profile_switcher_.Update(AvatarButtonStyle::NATIVE); |
| 177 else |
| 178 UpdateProfileIndicatorIcon(); |
| 127 } | 179 } |
| 128 | 180 |
| 129 /////////////////////////////////////////////////////////////////////////////// | 181 /////////////////////////////////////////////////////////////////////////////// |
| 130 // BrowserNonClientFrameViewMac, private: | 182 // BrowserNonClientFrameViewMac, private: |
| 131 | 183 |
| 184 int BrowserNonClientFrameViewMac::GetTabStripRightInset() const { |
| 185 int inset = kAvatarButtonPadding * 2; |
| 186 if (profile_indicator_icon()) |
| 187 inset += profile_indicator_icon()->width(); |
| 188 if (profile_switcher_.view()) |
| 189 inset += profile_switcher_.view()->width(); |
| 190 return inset; |
| 191 } |
| 192 |
| 132 void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) { | 193 void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) { |
| 133 gfx::ImageSkia image = GetFrameImage(); | 194 gfx::ImageSkia image = GetFrameImage(); |
| 134 canvas->TileImageInt(image, 0, 0, width(), image.height()); | 195 canvas->TileImageInt(image, 0, 0, width(), image.height()); |
| 135 gfx::ImageSkia overlay = GetFrameOverlayImage(); | 196 gfx::ImageSkia overlay = GetFrameOverlayImage(); |
| 136 canvas->TileImageInt(overlay, 0, 0, width(), overlay.height()); | 197 canvas->TileImageInt(overlay, 0, 0, width(), overlay.height()); |
| 137 } | 198 } |
| 138 | 199 |
| 139 void BrowserNonClientFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) { | 200 void BrowserNonClientFrameViewMac::PaintToolbarBackground(gfx::Canvas* canvas) { |
| 140 gfx::Rect bounds(browser_view()->GetToolbarBounds()); | 201 gfx::Rect bounds(browser_view()->GetToolbarBounds()); |
| 141 if (bounds.IsEmpty()) | 202 if (bounds.IsEmpty()) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 165 // Draw the tabstrip/toolbar separator. | 226 // Draw the tabstrip/toolbar separator. |
| 166 canvas->TileImageInt(*border, 0, 0, x, y, w, border->height()); | 227 canvas->TileImageInt(*border, 0, 0, x, y, w, border->height()); |
| 167 | 228 |
| 168 // Draw the content/toolbar separator. | 229 // Draw the content/toolbar separator. |
| 169 canvas->FillRect( | 230 canvas->FillRect( |
| 170 gfx::Rect(x, y + h - kClientEdgeThickness, w, kClientEdgeThickness), | 231 gfx::Rect(x, y + h - kClientEdgeThickness, w, kClientEdgeThickness), |
| 171 ThemeProperties::GetDefaultColor( | 232 ThemeProperties::GetDefaultColor( |
| 172 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR, | 233 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR, |
| 173 browser_view()->IsOffTheRecord())); | 234 browser_view()->IsOffTheRecord())); |
| 174 } | 235 } |
| OLD | NEW |