OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/glass_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/glass_browser_frame_view.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/themes/theme_service.h" | 13 #include "chrome/browser/themes/theme_service.h" |
14 #include "chrome/browser/ui/profile_menu_model.h" | |
15 #include "chrome/browser/ui/views/avatar_menu_button.h" | |
14 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
15 #include "chrome/browser/ui/views/profile_menu_button.h" | |
16 #include "chrome/browser/ui/views/profile_tag_view.h" | |
17 #include "chrome/browser/ui/views/tabs/side_tab_strip.h" | 17 #include "chrome/browser/ui/views/tabs/side_tab_strip.h" |
18 #include "chrome/browser/ui/views/tabs/tab.h" | 18 #include "chrome/browser/ui/views/tabs/tab.h" |
19 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 19 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
23 #include "grit/app_resources.h" | 23 #include "grit/app_resources.h" |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "grit/theme_resources_standard.h" | 26 #include "grit/theme_resources_standard.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
39 // There are 3 px of client edge drawn inside the outer frame borders. | 39 // There are 3 px of client edge drawn inside the outer frame borders. |
40 const int kNonClientBorderThickness = 3; | 40 const int kNonClientBorderThickness = 3; |
41 // Vertical tabs have 4 px border. | 41 // Vertical tabs have 4 px border. |
42 const int kNonClientVerticalTabStripBorderThickness = 4; | 42 const int kNonClientVerticalTabStripBorderThickness = 4; |
43 // Besides the frame border, there's another 11 px of empty space atop the | 43 // Besides the frame border, there's another 11 px of empty space atop the |
44 // window in restored mode, to use to drag the window around. | 44 // window in restored mode, to use to drag the window around. |
45 const int kNonClientRestoredExtraThickness = 11; | 45 const int kNonClientRestoredExtraThickness = 11; |
46 // In the window corners, the resize areas don't actually expand bigger, but the | 46 // In the window corners, the resize areas don't actually expand bigger, but the |
47 // 16 px at the end of the top and bottom edges triggers diagonal resizing. | 47 // 16 px at the end of the top and bottom edges triggers diagonal resizing. |
48 const int kResizeAreaCornerSize = 16; | 48 const int kResizeAreaCornerSize = 16; |
49 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the | 49 // The avatar ends 2 px above the bottom of the tabstrip (which, given the |
50 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the | 50 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the |
51 // user). | 51 // user). |
52 const int kOTRBottomSpacing = 2; | 52 const int kAvatarBottomSpacing = 2; |
53 // There are 2 px on each side of the OTR avatar (between the frame border and | 53 // There are 2 px on each side of the avatar (between the frame border and |
54 // it on the left, and between it and the tabstrip on the right). | 54 // it on the left, and between it and the tabstrip on the right). |
55 const int kOTRSideSpacing = 2; | 55 const int kAvatarSideSpacing = 2; |
56 // The content left/right images have a shadow built into them. | 56 // The content left/right images have a shadow built into them. |
57 const int kContentEdgeShadowThickness = 2; | 57 const int kContentEdgeShadowThickness = 2; |
58 // The top 1 px of the tabstrip is shadow; in maximized mode we push this off | 58 // The top 1 px of the tabstrip is shadow; in maximized mode we push this off |
59 // the top of the screen so the tabs appear flush against the screen edge. | 59 // the top of the screen so the tabs appear flush against the screen edge. |
60 const int kTabstripTopShadowThickness = 1; | 60 const int kTabstripTopShadowThickness = 1; |
61 // In restored mode, the New Tab button isn't at the same height as the caption | 61 // In restored mode, the New Tab button isn't at the same height as the caption |
62 // buttons, but the space will look cluttered if it actually slides under them, | 62 // buttons, but the space will look cluttered if it actually slides under them, |
63 // so we stop it when the gap between the two is down to 5 px. | 63 // so we stop it when the gap between the two is down to 5 px. |
64 const int kNewTabCaptionRestoredSpacing = 5; | 64 const int kNewTabCaptionRestoredSpacing = 5; |
65 // In maximized mode, where the New Tab button and the caption buttons are at | 65 // In maximized mode, where the New Tab button and the caption buttons are at |
66 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid | 66 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid |
67 // looking too cluttered. | 67 // looking too cluttered. |
68 const int kNewTabCaptionMaximizedSpacing = 16; | 68 const int kNewTabCaptionMaximizedSpacing = 16; |
69 // Y position for profile button inside the frame. | |
70 const int kProfileButtonYPosition = 2; | |
71 // Y position for profile tag inside the frame. | |
72 const int kProfileTagYPosition = 1; | |
73 // Offset y position of profile button and tag by this amount when maximized. | |
74 const int kProfileElementMaximizedYOffset = 6; | |
75 } | 69 } |
76 | 70 |
77 /////////////////////////////////////////////////////////////////////////////// | 71 /////////////////////////////////////////////////////////////////////////////// |
78 // GlassBrowserFrameView, public: | 72 // GlassBrowserFrameView, public: |
79 | 73 |
80 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, | 74 GlassBrowserFrameView::GlassBrowserFrameView(BrowserFrame* frame, |
81 BrowserView* browser_view) | 75 BrowserView* browser_view) |
82 : BrowserNonClientFrameView(), | 76 : BrowserNonClientFrameView(), |
83 frame_(frame), | 77 frame_(frame), |
84 browser_view_(browser_view), | 78 browser_view_(browser_view), |
85 throbber_running_(false), | 79 throbber_running_(false), |
86 throbber_frame_(0) { | 80 throbber_frame_(0) { |
87 if (browser_view_->ShouldShowWindowIcon()) | 81 if (browser_view_->ShouldShowWindowIcon()) |
88 InitThrobberIcons(); | 82 InitThrobberIcons(); |
89 // If multi-profile is enabled set up profile button and login notifications. | 83 |
84 if (browser_view_->ShouldShowAvatar()) { | |
85 ui::MenuModel* menu_model = browser_view_->IsOffTheRecord() ? | |
sky
2011/06/09 15:46:46
Dcoument that AvatarMenuButton takes ownership of
| |
86 NULL : new ProfileMenuModel; | |
Peter Kasting
2011/06/09 18:03:31
FWIW, I think the OTR avatar should function as a
| |
87 avatar_button_.reset(new AvatarMenuButton(std::wstring(), menu_model)); | |
88 AddChildView(avatar_button_.get()); | |
89 | |
90 if (browser_view_->IsOffTheRecord()) { | |
91 avatar_button_->SetIcon(browser_view_->GetOTRAvatarIcon()); | |
92 } else { | |
93 // TODO(sail) Get the avatar icon assigned to this profile. | |
94 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
95 avatar_button_->SetIcon(*rb.GetBitmapNamed(IDR_PROFILE_AVATAR_1)); | |
96 // TODO(sail) Also need to call SetHoverIcon() and SetPushedIcon(). | |
97 } | |
98 } | |
99 | |
100 // If multi-profile is enabled set up login notifications. | |
90 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 101 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); |
91 if (browser_command_line.HasSwitch(switches::kMultiProfiles) && | 102 if (browser_command_line.HasSwitch(switches::kMultiProfiles) && |
92 !browser_view->ShouldShowOffTheRecordAvatar()) { | 103 !browser_view->IsOffTheRecord()) { |
93 RegisterLoginNotifications(); | 104 RegisterLoginNotifications(); |
94 profile_button_.reset(new ProfileMenuButton(std::wstring(), | |
95 browser_view_->browser()->profile())); | |
96 profile_button_->SetVisible(false); | |
97 profile_tag_.reset(new ProfileTagView(frame_, profile_button_.get())); | |
98 profile_tag_->SetVisible(false); | |
99 AddChildView(profile_tag_.get()); | |
100 AddChildView(profile_button_.get()); | |
101 } | 105 } |
102 } | 106 } |
103 | 107 |
104 GlassBrowserFrameView::~GlassBrowserFrameView() { | 108 GlassBrowserFrameView::~GlassBrowserFrameView() { |
105 } | 109 } |
106 | 110 |
107 /////////////////////////////////////////////////////////////////////////////// | 111 /////////////////////////////////////////////////////////////////////////////// |
108 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: | 112 // GlassBrowserFrameView, BrowserNonClientFrameView implementation: |
109 | 113 |
110 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( | 114 gfx::Rect GlassBrowserFrameView::GetBoundsForTabStrip( |
111 views::View* tabstrip) const { | 115 views::View* tabstrip) const { |
112 if (browser_view_->UseVerticalTabs()) { | 116 if (browser_view_->UseVerticalTabs()) { |
113 gfx::Size ps = tabstrip->GetPreferredSize(); | 117 gfx::Size ps = tabstrip->GetPreferredSize(); |
114 return gfx::Rect(NonClientBorderThickness(), | 118 return gfx::Rect(NonClientBorderThickness(), |
115 NonClientTopBorderHeight(false, false), ps.width(), | 119 NonClientTopBorderHeight(false, false), ps.width(), |
116 browser_view_->height()); | 120 browser_view_->height()); |
117 } | 121 } |
118 int minimize_button_offset = | 122 int minimize_button_offset = |
119 std::min(frame_->GetMinimizeButtonOffset(), width()); | 123 std::min(frame_->GetMinimizeButtonOffset(), width()); |
120 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? | 124 int tabstrip_x = browser_view_->ShouldShowAvatar() ? |
121 (otr_avatar_bounds_.right() + kOTRSideSpacing) : | 125 (avatar_bounds_.right() + kAvatarSideSpacing) : |
122 NonClientBorderThickness(); | 126 NonClientBorderThickness(); |
123 // In RTL languages, we have moved an avatar icon left by the size of window | 127 // In RTL languages, we have moved an avatar icon left by the size of window |
124 // controls to prevent it from being rendered over them. So, we use its x | 128 // controls to prevent it from being rendered over them. So, we use its x |
125 // position to move this tab strip left when maximized. Also, we can render | 129 // position to move this tab strip left when maximized. Also, we can render |
126 // a tab strip until the left end of this window without considering the size | 130 // a tab strip until the left end of this window without considering the size |
127 // of window controls in RTL languages. | 131 // of window controls in RTL languages. |
128 if (base::i18n::IsRTL()) { | 132 if (base::i18n::IsRTL()) { |
129 if (!browser_view_->ShouldShowOffTheRecordAvatar() && frame_->IsMaximized()) | 133 if (!browser_view_->ShouldShowAvatar() && frame_->IsMaximized()) |
130 tabstrip_x += otr_avatar_bounds_.x(); | 134 tabstrip_x += avatar_bounds_.x(); |
131 minimize_button_offset = width(); | 135 minimize_button_offset = width(); |
132 } | 136 } |
133 int maximized_spacing = | 137 int maximized_spacing = kNewTabCaptionMaximizedSpacing; |
134 kNewTabCaptionMaximizedSpacing + | |
135 (show_profile_button() && profile_button_->IsVisible() ? | |
136 profile_button_->GetPreferredSize().width() + | |
137 ProfileMenuButton::kProfileTagHorizontalSpacing : 0); | |
138 int tabstrip_width = minimize_button_offset - tabstrip_x - | 138 int tabstrip_width = minimize_button_offset - tabstrip_x - |
139 (frame_->IsMaximized() ? | 139 (frame_->IsMaximized() ? |
140 maximized_spacing : kNewTabCaptionRestoredSpacing); | 140 maximized_spacing : kNewTabCaptionRestoredSpacing); |
141 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false), | 141 return gfx::Rect(tabstrip_x, GetHorizontalTabStripVerticalOffset(false), |
142 std::max(0, tabstrip_width), | 142 std::max(0, tabstrip_width), |
143 tabstrip->GetPreferredSize().height()); | 143 tabstrip->GetPreferredSize().height()); |
144 } | 144 } |
145 | 145 |
146 int GlassBrowserFrameView::GetHorizontalTabStripVerticalOffset( | 146 int GlassBrowserFrameView::GetHorizontalTabStripVerticalOffset( |
147 bool restored) const { | 147 bool restored) const { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { | 192 int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) { |
193 // If the browser isn't in normal mode, we haven't customized the frame, so | 193 // If the browser isn't in normal mode, we haven't customized the frame, so |
194 // Windows can figure this out. If the point isn't within our bounds, then | 194 // Windows can figure this out. If the point isn't within our bounds, then |
195 // it's in the native portion of the frame, so again Windows can figure it | 195 // it's in the native portion of the frame, so again Windows can figure it |
196 // out. | 196 // out. |
197 if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point)) | 197 if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point)) |
198 return HTNOWHERE; | 198 return HTNOWHERE; |
199 | 199 |
200 int frame_component = frame_->client_view()->NonClientHitTest(point); | 200 int frame_component = frame_->client_view()->NonClientHitTest(point); |
201 | 201 |
202 // See if the point is within the avatar menu button. | |
sky
2011/06/09 15:46:46
Move this above 200.
sail
2011/06/10 00:56:20
Done.
| |
203 if (avatar_button_.get() && | |
204 avatar_button_->GetMirroredBounds().Contains(point)) | |
205 return HTCLIENT; | |
206 | |
202 // See if we're in the sysmenu region. We still have to check the tabstrip | 207 // See if we're in the sysmenu region. We still have to check the tabstrip |
203 // first so that clicks in a tab don't get treated as sysmenu clicks. | 208 // first so that clicks in a tab don't get treated as sysmenu clicks. |
204 int nonclient_border_thickness = NonClientBorderThickness(); | 209 int nonclient_border_thickness = NonClientBorderThickness(); |
205 if (gfx::Rect(nonclient_border_thickness, GetSystemMetrics(SM_CXSIZEFRAME), | 210 if (gfx::Rect(nonclient_border_thickness, GetSystemMetrics(SM_CXSIZEFRAME), |
206 GetSystemMetrics(SM_CXSMICON), | 211 GetSystemMetrics(SM_CXSMICON), |
207 GetSystemMetrics(SM_CYSMICON)).Contains(point)) | 212 GetSystemMetrics(SM_CYSMICON)).Contains(point)) |
208 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; | 213 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; |
209 | 214 |
210 if (frame_component != HTNOWHERE) | 215 if (frame_component != HTNOWHERE) |
211 return frame_component; | 216 return frame_component; |
212 | 217 |
213 // See if the point is within the profile menu button. | |
214 if (show_profile_button() && profile_button_->IsVisible() && | |
215 profile_button_->GetMirroredBounds().Contains(point)) | |
216 return HTCLIENT; | |
217 | |
218 int frame_border_thickness = FrameBorderThickness(); | 218 int frame_border_thickness = FrameBorderThickness(); |
219 int window_component = GetHTComponentForFrame(point, frame_border_thickness, | 219 int window_component = GetHTComponentForFrame(point, frame_border_thickness, |
220 nonclient_border_thickness, frame_border_thickness, | 220 nonclient_border_thickness, frame_border_thickness, |
221 kResizeAreaCornerSize - frame_border_thickness, | 221 kResizeAreaCornerSize - frame_border_thickness, |
222 frame_->window_delegate()->CanResize()); | 222 frame_->window_delegate()->CanResize()); |
223 // Fall back to the caption if no other component matches. | 223 // Fall back to the caption if no other component matches. |
224 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 224 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
225 } | 225 } |
226 | 226 |
227 /////////////////////////////////////////////////////////////////////////////// | 227 /////////////////////////////////////////////////////////////////////////////// |
228 // GlassBrowserFrameView, views::View overrides: | 228 // GlassBrowserFrameView, views::View overrides: |
229 | 229 |
230 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { | 230 void GlassBrowserFrameView::OnPaint(gfx::Canvas* canvas) { |
231 if (!browser_view_->IsTabStripVisible()) | 231 if (!browser_view_->IsTabStripVisible()) |
232 return; // Nothing is visible, so don't bother to paint. | 232 return; // Nothing is visible, so don't bother to paint. |
233 | 233 |
234 PaintToolbarBackground(canvas); | 234 PaintToolbarBackground(canvas); |
235 if (browser_view_->ShouldShowOffTheRecordAvatar()) | |
236 PaintOTRAvatar(canvas); | |
237 if (!frame_->IsMaximized()) | 235 if (!frame_->IsMaximized()) |
238 PaintRestoredClientEdge(canvas); | 236 PaintRestoredClientEdge(canvas); |
239 } | 237 } |
240 | 238 |
241 void GlassBrowserFrameView::Layout() { | 239 void GlassBrowserFrameView::Layout() { |
242 LayoutOTRAvatar(); | 240 LayoutAvatar(); |
243 LayoutClientView(); | 241 LayoutClientView(); |
244 LayoutProfileTag(); | |
245 } | 242 } |
246 | 243 |
247 bool GlassBrowserFrameView::HitTest(const gfx::Point& l) const { | 244 bool GlassBrowserFrameView::HitTest(const gfx::Point& l) const { |
248 // The ProfileMenuButton intrudes into the client area when the window is | 245 // The AvatarMenuButton intrudes into the client area when the window is |
249 // maximized. | 246 // maximized. |
250 return (frame_->IsMaximized() && show_profile_button() && | 247 return (frame_->IsMaximized() && avatar_button_.get() && |
251 profile_button_->IsVisible() && | 248 avatar_button_->IsVisible() && |
252 profile_button_->GetMirroredBounds().Contains(l)) || | 249 avatar_button_->GetMirroredBounds().Contains(l)) || |
253 !frame_->client_view()->bounds().Contains(l); | 250 !frame_->client_view()->bounds().Contains(l); |
254 } | 251 } |
255 | 252 |
256 /////////////////////////////////////////////////////////////////////////////// | 253 /////////////////////////////////////////////////////////////////////////////// |
257 // GlassBrowserFrameView, private: | 254 // GlassBrowserFrameView, private: |
258 | 255 |
259 int GlassBrowserFrameView::FrameBorderThickness() const { | 256 int GlassBrowserFrameView::FrameBorderThickness() const { |
260 return (frame_->IsMaximized() || frame_->IsFullscreen()) ? | 257 return (frame_->IsMaximized() || frame_->IsFullscreen()) ? |
261 0 : GetSystemMetrics(SM_CXSIZEFRAME); | 258 0 : GetSystemMetrics(SM_CXSIZEFRAME); |
262 } | 259 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 canvas->DrawBitmapInt(*tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER), | 372 canvas->DrawBitmapInt(*tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER), |
376 right_x, y); | 373 right_x, y); |
377 } | 374 } |
378 | 375 |
379 // Draw the content/toolbar separator. | 376 // Draw the content/toolbar separator. |
380 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, | 377 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, |
381 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness, | 378 x + kClientEdgeThickness, toolbar_bounds.bottom() - kClientEdgeThickness, |
382 w - (2 * kClientEdgeThickness), kClientEdgeThickness); | 379 w - (2 * kClientEdgeThickness), kClientEdgeThickness); |
383 } | 380 } |
384 | 381 |
385 void GlassBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) { | |
386 // In RTL mode, the avatar icon should be looking the opposite direction. | |
387 canvas->Save(); | |
388 if (base::i18n::IsRTL()) { | |
389 canvas->TranslateInt(width(), 0); | |
390 canvas->ScaleInt(-1, 1); | |
391 } | |
392 | |
393 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); | |
394 int w = otr_avatar_bounds_.width(); | |
395 int h = otr_avatar_bounds_.height(); | |
396 canvas->DrawBitmapInt(otr_avatar_icon, 0, | |
397 // Bias the rounding to select a region that's lower rather than higher, | |
398 // as the shadows at the image top mean the apparent center is below the | |
399 // real center. | |
400 ((otr_avatar_icon.height() - otr_avatar_bounds_.height()) + 1) / 2, w, h, | |
401 otr_avatar_bounds_.x(), otr_avatar_bounds_.y(), w, h, false); | |
402 | |
403 canvas->Restore(); | |
404 } | |
405 | |
406 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { | 382 void GlassBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { |
407 ui::ThemeProvider* tp = GetThemeProvider(); | 383 ui::ThemeProvider* tp = GetThemeProvider(); |
408 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); | 384 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); |
409 | 385 |
410 // The client edges start below the toolbar upper corner images regardless | 386 // The client edges start below the toolbar upper corner images regardless |
411 // of how tall the toolbar itself is. | 387 // of how tall the toolbar itself is. |
412 int client_area_top = browser_view_->UseVerticalTabs() ? | 388 int client_area_top = browser_view_->UseVerticalTabs() ? |
413 client_area_bounds.y() : | 389 client_area_bounds.y() : |
414 (frame_->client_view()->y() + | 390 (frame_->client_view()->y() + |
415 browser_view_->GetToolbarBounds().y() + | 391 browser_view_->GetToolbarBounds().y() + |
(...skipping 30 matching lines...) Expand all Loading... | |
446 client_area_bounds.x() - kClientEdgeThickness, client_area_top, | 422 client_area_bounds.x() - kClientEdgeThickness, client_area_top, |
447 kClientEdgeThickness, | 423 kClientEdgeThickness, |
448 client_area_bottom + kClientEdgeThickness - client_area_top); | 424 client_area_bottom + kClientEdgeThickness - client_area_top); |
449 canvas->FillRectInt(toolbar_color, client_area_bounds.x(), client_area_bottom, | 425 canvas->FillRectInt(toolbar_color, client_area_bounds.x(), client_area_bottom, |
450 client_area_bounds.width(), kClientEdgeThickness); | 426 client_area_bounds.width(), kClientEdgeThickness); |
451 canvas->FillRectInt(toolbar_color, client_area_bounds.right(), | 427 canvas->FillRectInt(toolbar_color, client_area_bounds.right(), |
452 client_area_top, kClientEdgeThickness, | 428 client_area_top, kClientEdgeThickness, |
453 client_area_bottom + kClientEdgeThickness - client_area_top); | 429 client_area_bottom + kClientEdgeThickness - client_area_top); |
454 } | 430 } |
455 | 431 |
456 void GlassBrowserFrameView::LayoutOTRAvatar() { | 432 void GlassBrowserFrameView::LayoutAvatar() { |
457 int otr_x = NonClientBorderThickness() + kOTRSideSpacing; | 433 int avatar_x = NonClientBorderThickness() + kAvatarSideSpacing; |
458 // Move this avatar icon by the size of window controls to prevent it from | 434 // Move this avatar icon by the size of window controls to prevent it from |
459 // being rendered over them in RTL languages. This code also needs to adjust | 435 // being rendered over them in RTL languages. This code also needs to adjust |
460 // the width of a tab strip to avoid decreasing this size twice. (See the | 436 // the width of a tab strip to avoid decreasing this size twice. (See the |
461 // comment in GetBoundsForTabStrip().) | 437 // comment in GetBoundsForTabStrip().) |
462 if (base::i18n::IsRTL()) | 438 if (base::i18n::IsRTL()) |
463 otr_x += width() - frame_->GetMinimizeButtonOffset(); | 439 avatar_x += width() - frame_->GetMinimizeButtonOffset(); |
464 | 440 |
465 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); | 441 // Even though the avatar is used for both incognito and profiles we always |
466 int otr_bottom, otr_restored_y; | 442 // use the incognito icon to layout the avatar button. |
Peter Kasting
2011/06/09 18:03:31
Why?
sail
2011/06/10 00:56:20
Changed to hard code the button size.
| |
443 SkBitmap incognito_icon = browser_view_->GetOTRAvatarIcon(); | |
444 | |
445 int avatar_bottom, avatar_restored_y; | |
467 if (browser_view_->UseVerticalTabs()) { | 446 if (browser_view_->UseVerticalTabs()) { |
468 otr_bottom = NonClientTopBorderHeight(false, false) - kOTRBottomSpacing; | 447 avatar_bottom = NonClientTopBorderHeight(false, false) - |
469 otr_restored_y = kFrameShadowThickness; | 448 kAvatarBottomSpacing; |
449 avatar_restored_y = kFrameShadowThickness; | |
470 } else { | 450 } else { |
471 otr_bottom = GetHorizontalTabStripVerticalOffset(false) + | 451 avatar_bottom = GetHorizontalTabStripVerticalOffset(false) + |
472 browser_view_->GetTabStripHeight() - kOTRBottomSpacing; | 452 browser_view_->GetTabStripHeight() - kAvatarBottomSpacing; |
473 otr_restored_y = otr_bottom - otr_avatar_icon.height(); | 453 avatar_restored_y = avatar_bottom - incognito_icon.height(); |
474 } | 454 } |
475 int otr_y = frame_->IsMaximized() ? | 455 int avatar_y = frame_->IsMaximized() ? |
476 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : | 456 (NonClientTopBorderHeight(false, true) + kTabstripTopShadowThickness) : |
477 otr_restored_y; | 457 avatar_restored_y; |
478 otr_avatar_bounds_.SetRect(otr_x, otr_y, otr_avatar_icon.width(), | 458 avatar_bounds_.SetRect(avatar_x, avatar_y, incognito_icon.width(), |
479 browser_view_->ShouldShowOffTheRecordAvatar() ? (otr_bottom - otr_y) : 0); | 459 browser_view_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); |
460 | |
461 if (avatar_button_.get()) | |
462 avatar_button_->SetBoundsRect(avatar_bounds_); | |
480 } | 463 } |
481 | 464 |
482 void GlassBrowserFrameView::LayoutClientView() { | 465 void GlassBrowserFrameView::LayoutClientView() { |
483 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); | 466 client_view_bounds_ = CalculateClientAreaBounds(width(), height()); |
484 } | 467 } |
485 | 468 |
486 void GlassBrowserFrameView::LayoutProfileTag() { | |
487 if (!show_profile_button()) | |
488 return; | |
489 | |
490 string16 profile_name = UTF8ToUTF16(browser_view_->browser()->profile()-> | |
491 GetPrefs()->GetString(prefs::kGoogleServicesUsername)); | |
492 if (!profile_name.empty()) { | |
493 profile_button_->SetText(profile_name); | |
494 profile_button_->SetTextShadowColors( | |
495 ProfileMenuButton::kDefaultActiveTextShadow, | |
496 ProfileMenuButton::kDefaultInactiveTextShadow); | |
497 } else { | |
498 profile_button_->SetText(l10n_util::GetStringUTF16( | |
499 IDS_PROFILES_NOT_SIGNED_IN_MENU)); | |
500 profile_button_->SetTextShadowColors( | |
501 ProfileMenuButton::kDarkTextShadow, | |
502 ProfileMenuButton::kDefaultInactiveTextShadow); | |
503 } | |
504 | |
505 profile_button_->ClearMaxTextSize(); | |
506 profile_button_->SetVisible(true); | |
507 int x_tag = | |
508 // The x position of minimize button in the frame | |
509 frame_->GetMinimizeButtonOffset() - | |
510 // - the space between the minimize button and the profile button | |
511 ProfileMenuButton::kProfileTagHorizontalSpacing - | |
512 // - the width of the profile button | |
513 profile_button_->GetPreferredSize().width(); | |
514 int y_maximized_offset = frame_->IsMaximized() ? | |
515 kProfileElementMaximizedYOffset : 0; | |
516 profile_button_->SetBounds( | |
517 x_tag, | |
518 kProfileButtonYPosition + y_maximized_offset, | |
519 profile_button_->GetPreferredSize().width(), | |
520 profile_button_->GetPreferredSize().height()); | |
521 | |
522 profile_tag_->SetVisible(true); | |
523 profile_tag_->set_is_signed_in(!profile_name.empty()); | |
524 profile_tag_->SetBounds( | |
525 x_tag, | |
526 kProfileTagYPosition + y_maximized_offset, | |
527 profile_button_->GetPreferredSize().width(), | |
528 ProfileTagView::kProfileTagHeight); | |
529 } | |
530 | |
531 gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width, | 469 gfx::Rect GlassBrowserFrameView::CalculateClientAreaBounds(int width, |
532 int height) const { | 470 int height) const { |
533 if (!browser_view_->IsTabStripVisible()) | 471 if (!browser_view_->IsTabStripVisible()) |
534 return gfx::Rect(0, 0, this->width(), this->height()); | 472 return gfx::Rect(0, 0, this->width(), this->height()); |
535 | 473 |
536 int top_height = NonClientTopBorderHeight(false, false); | 474 int top_height = NonClientTopBorderHeight(false, false); |
537 int border_thickness = NonClientBorderThickness(); | 475 int border_thickness = NonClientBorderThickness(); |
538 return gfx::Rect(border_thickness, top_height, | 476 return gfx::Rect(border_thickness, top_height, |
539 std::max(0, width - (2 * border_thickness)), | 477 std::max(0, width - (2 * border_thickness)), |
540 std::max(0, height - top_height - border_thickness)); | 478 std::max(0, height - top_height - border_thickness)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 static_cast<WPARAM>(ICON_SMALL), | 523 static_cast<WPARAM>(ICON_SMALL), |
586 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); | 524 reinterpret_cast<LPARAM>(throbber_icons_[throbber_frame_])); |
587 } | 525 } |
588 | 526 |
589 void GlassBrowserFrameView::Observe(NotificationType type, | 527 void GlassBrowserFrameView::Observe(NotificationType type, |
590 const NotificationSource& source, | 528 const NotificationSource& source, |
591 const NotificationDetails& details) { | 529 const NotificationDetails& details) { |
592 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); | 530 DCHECK_EQ(NotificationType::PREF_CHANGED, type.value); |
593 std::string* name = Details<std::string>(details).ptr(); | 531 std::string* name = Details<std::string>(details).ptr(); |
594 if (prefs::kGoogleServicesUsername == *name) | 532 if (prefs::kGoogleServicesUsername == *name) |
595 LayoutProfileTag(); | 533 LayoutAvatar(); |
596 } | 534 } |
597 | 535 |
598 void GlassBrowserFrameView::RegisterLoginNotifications() { | 536 void GlassBrowserFrameView::RegisterLoginNotifications() { |
599 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); | 537 PrefService* pref_service = browser_view_->browser()->profile()->GetPrefs(); |
600 DCHECK(pref_service); | 538 DCHECK(pref_service); |
601 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); | 539 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); |
602 } | 540 } |
603 | 541 |
604 // static | 542 // static |
605 void GlassBrowserFrameView::InitThrobberIcons() { | 543 void GlassBrowserFrameView::InitThrobberIcons() { |
606 static bool initialized = false; | 544 static bool initialized = false; |
607 if (!initialized) { | 545 if (!initialized) { |
608 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | 546 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
609 for (int i = 0; i < kThrobberIconCount; ++i) { | 547 for (int i = 0; i < kThrobberIconCount; ++i) { |
610 throbber_icons_[i] = rb.LoadThemeIcon(IDI_THROBBER_01 + i); | 548 throbber_icons_[i] = rb.LoadThemeIcon(IDI_THROBBER_01 + i); |
611 DCHECK(throbber_icons_[i]); | 549 DCHECK(throbber_icons_[i]); |
612 } | 550 } |
613 initialized = true; | 551 initialized = true; |
614 } | 552 } |
615 } | 553 } |
OLD | NEW |