Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_aura.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_aura.h" |
| 6 | 6 |
| 7 #include "ash/wm/frame_painter.h" | 7 #include "ash/wm/frame_painter.h" |
| 8 #include "ash/wm/workspace/frame_maximize_button.h" | 8 #include "ash/wm/workspace/frame_maximize_button.h" |
| 9 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
| 10 #include "chrome/browser/ui/views/avatar_menu_button.h" | 10 #include "chrome/browser/ui/views/avatar_menu_button.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 const int kContentShadowHeight = 1; | 54 const int kContentShadowHeight = 1; |
| 55 | 55 |
| 56 } // namespace | 56 } // namespace |
| 57 | 57 |
| 58 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
| 59 // BrowserNonClientFrameViewAura, public: | 59 // BrowserNonClientFrameViewAura, public: |
| 60 | 60 |
| 61 BrowserNonClientFrameViewAura::BrowserNonClientFrameViewAura( | 61 BrowserNonClientFrameViewAura::BrowserNonClientFrameViewAura( |
| 62 BrowserFrame* frame, BrowserView* browser_view) | 62 BrowserFrame* frame, BrowserView* browser_view) |
| 63 : BrowserNonClientFrameView(frame, browser_view), | 63 : BrowserNonClientFrameView(frame, browser_view), |
| 64 maximize_button_(NULL), | 64 size_button_(NULL), |
| 65 close_button_(NULL), | 65 close_button_(NULL), |
| 66 window_icon_(NULL), | 66 window_icon_(NULL), |
| 67 frame_painter_(new ash::FramePainter) { | 67 frame_painter_(new ash::FramePainter), |
| 68 size_button_minimizes_(false) { | |
|
James Cook
2012/03/31 00:15:09
nit: Maybe this could be size_button_behavior_?
| |
| 68 } | 69 } |
| 69 | 70 |
| 70 BrowserNonClientFrameViewAura::~BrowserNonClientFrameViewAura() { | 71 BrowserNonClientFrameViewAura::~BrowserNonClientFrameViewAura() { |
| 71 } | 72 } |
| 72 | 73 |
| 73 void BrowserNonClientFrameViewAura::Init() { | 74 void BrowserNonClientFrameViewAura::Init() { |
| 74 // Caption buttons. | 75 // Panels only minimize. |
| 75 maximize_button_ = new ash::FrameMaximizeButton(this, this); | 76 ash::FramePainter::SizeButtonBehavior size_button_behavior; |
| 76 maximize_button_->SetAccessibleName( | 77 if (browser_view()->browser()->is_type_panel() && |
| 78 browser_view()->browser()->app_type() == Browser::APP_TYPE_CHILD) { | |
| 79 size_button_minimizes_ = true; | |
| 80 size_button_ = new views::ImageButton(this); | |
| 81 size_button_behavior = ash::FramePainter::SIZE_BUTTON_MINIMIZES; | |
| 82 } else { | |
| 83 size_button_ = new ash::FrameMaximizeButton(this, this); | |
| 84 size_button_behavior = ash::FramePainter::SIZE_BUTTON_MAXIMIZES; | |
| 85 } | |
| 86 size_button_->SetAccessibleName( | |
| 77 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); | 87 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); |
| 78 AddChildView(maximize_button_); | 88 AddChildView(size_button_); |
| 79 close_button_ = new views::ImageButton(this); | 89 close_button_ = new views::ImageButton(this); |
| 80 close_button_->SetAccessibleName( | 90 close_button_->SetAccessibleName( |
| 81 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 91 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 82 AddChildView(close_button_); | 92 AddChildView(close_button_); |
| 83 | 93 |
| 84 // Initializing the TabIconView is expensive, so only do it if we need to. | 94 // Initializing the TabIconView is expensive, so only do it if we need to. |
| 85 if (browser_view()->ShouldShowWindowIcon()) { | 95 if (browser_view()->ShouldShowWindowIcon()) { |
| 86 window_icon_ = new TabIconView(this); | 96 window_icon_ = new TabIconView(this); |
| 87 window_icon_->set_is_light(true); | 97 window_icon_->set_is_light(true); |
| 88 AddChildView(window_icon_); | 98 AddChildView(window_icon_); |
| 89 window_icon_->Update(); | 99 window_icon_->Update(); |
| 90 } | 100 } |
| 91 | 101 |
| 92 // Create incognito icon if necessary. | 102 // Create incognito icon if necessary. |
| 93 UpdateAvatarInfo(); | 103 UpdateAvatarInfo(); |
| 94 | 104 |
| 95 // Frame painter handles layout of these buttons. | 105 // Frame painter handles layout of these buttons. |
| 96 frame_painter_->Init(frame(), window_icon_, maximize_button_, close_button_); | 106 frame_painter_->Init(frame(), window_icon_, size_button_, close_button_, |
| 107 size_button_behavior); | |
| 97 } | 108 } |
| 98 | 109 |
| 99 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
| 100 // BrowserNonClientFrameView overrides: | 111 // BrowserNonClientFrameView overrides: |
| 101 | 112 |
| 102 gfx::Rect BrowserNonClientFrameViewAura::GetBoundsForTabStrip( | 113 gfx::Rect BrowserNonClientFrameViewAura::GetBoundsForTabStrip( |
| 103 views::View* tabstrip) const { | 114 views::View* tabstrip) const { |
| 104 if (!tabstrip) | 115 if (!tabstrip) |
| 105 return gfx::Rect(); | 116 return gfx::Rect(); |
| 106 int tabstrip_x = | 117 int tabstrip_x = |
| 107 avatar_button() ? | 118 avatar_button() ? |
| 108 (avatar_button()->bounds().right() + kAvatarSideSpacing) : | 119 (avatar_button()->bounds().right() + kAvatarSideSpacing) : |
| 109 kTabstripLeftSpacing; | 120 kTabstripLeftSpacing; |
| 110 int tabstrip_width = | 121 int tabstrip_width = |
| 111 maximize_button_->x() - kTabstripRightSpacing - tabstrip_x; | 122 size_button_->x() - kTabstripRightSpacing - tabstrip_x; |
| 112 return gfx::Rect(tabstrip_x, | 123 return gfx::Rect(tabstrip_x, |
| 113 GetHorizontalTabStripVerticalOffset(false), | 124 GetHorizontalTabStripVerticalOffset(false), |
| 114 std::max(0, tabstrip_width), | 125 std::max(0, tabstrip_width), |
| 115 tabstrip->GetPreferredSize().height()); | 126 tabstrip->GetPreferredSize().height()); |
| 116 } | 127 } |
| 117 | 128 |
| 118 int BrowserNonClientFrameViewAura::GetHorizontalTabStripVerticalOffset( | 129 int BrowserNonClientFrameViewAura::GetHorizontalTabStripVerticalOffset( |
| 119 bool force_restored) const { | 130 bool force_restored) const { |
| 120 return NonClientTopBorderHeight(force_restored); | 131 return NonClientTopBorderHeight(force_restored); |
| 121 } | 132 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 } | 166 } |
| 156 return hit_test; | 167 return hit_test; |
| 157 } | 168 } |
| 158 | 169 |
| 159 void BrowserNonClientFrameViewAura::GetWindowMask(const gfx::Size& size, | 170 void BrowserNonClientFrameViewAura::GetWindowMask(const gfx::Size& size, |
| 160 gfx::Path* window_mask) { | 171 gfx::Path* window_mask) { |
| 161 // Aura does not use window masks. | 172 // Aura does not use window masks. |
| 162 } | 173 } |
| 163 | 174 |
| 164 void BrowserNonClientFrameViewAura::ResetWindowControls() { | 175 void BrowserNonClientFrameViewAura::ResetWindowControls() { |
| 165 maximize_button_->SetState(views::CustomButton::BS_NORMAL); | 176 size_button_->SetState(views::CustomButton::BS_NORMAL); |
| 166 // The close button isn't affected by this constraint. | 177 // The close button isn't affected by this constraint. |
| 167 } | 178 } |
| 168 | 179 |
| 169 void BrowserNonClientFrameViewAura::UpdateWindowIcon() { | 180 void BrowserNonClientFrameViewAura::UpdateWindowIcon() { |
| 170 if (window_icon_) | 181 if (window_icon_) |
| 171 window_icon_->SchedulePaint(); | 182 window_icon_->SchedulePaint(); |
| 172 } | 183 } |
| 173 | 184 |
| 174 /////////////////////////////////////////////////////////////////////////////// | 185 /////////////////////////////////////////////////////////////////////////////// |
| 175 // views::View overrides: | 186 // views::View overrides: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 | 245 |
| 235 gfx::Size BrowserNonClientFrameViewAura::GetMinimumSize() { | 246 gfx::Size BrowserNonClientFrameViewAura::GetMinimumSize() { |
| 236 return frame_painter_->GetMinimumSize(this); | 247 return frame_painter_->GetMinimumSize(this); |
| 237 } | 248 } |
| 238 | 249 |
| 239 /////////////////////////////////////////////////////////////////////////////// | 250 /////////////////////////////////////////////////////////////////////////////// |
| 240 // views::ButtonListener overrides: | 251 // views::ButtonListener overrides: |
| 241 | 252 |
| 242 void BrowserNonClientFrameViewAura::ButtonPressed(views::Button* sender, | 253 void BrowserNonClientFrameViewAura::ButtonPressed(views::Button* sender, |
| 243 const views::Event& event) { | 254 const views::Event& event) { |
| 244 if (sender == maximize_button_) { | 255 if (sender == size_button_) { |
| 245 // The maximize button may move out from under the cursor. | 256 // The maximize button may move out from under the cursor. |
| 246 ResetWindowControls(); | 257 ResetWindowControls(); |
| 247 if (frame()->IsMaximized()) | 258 if (size_button_minimizes_) |
| 259 frame()->Minimize(); | |
| 260 else if (frame()->IsMaximized()) | |
| 248 frame()->Restore(); | 261 frame()->Restore(); |
| 249 else | 262 else |
| 250 frame()->Maximize(); | 263 frame()->Maximize(); |
| 251 // |this| may be deleted - some windows delete their frames on maximize. | 264 // |this| may be deleted - some windows delete their frames on maximize. |
| 252 } else if (sender == close_button_) { | 265 } else if (sender == close_button_) { |
| 253 frame()->Close(); | 266 frame()->Close(); |
| 254 } | 267 } |
| 255 } | 268 } |
| 256 | 269 |
| 257 /////////////////////////////////////////////////////////////////////////////// | 270 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 } | 448 } |
| 436 | 449 |
| 437 SkBitmap* BrowserNonClientFrameViewAura::GetCustomBitmap( | 450 SkBitmap* BrowserNonClientFrameViewAura::GetCustomBitmap( |
| 438 int bitmap_id, | 451 int bitmap_id, |
| 439 int fallback_bitmap_id) const { | 452 int fallback_bitmap_id) const { |
| 440 ui::ThemeProvider* tp = GetThemeProvider(); | 453 ui::ThemeProvider* tp = GetThemeProvider(); |
| 441 if (tp->HasCustomImage(bitmap_id)) | 454 if (tp->HasCustomImage(bitmap_id)) |
| 442 return tp->GetBitmapNamed(bitmap_id); | 455 return tp->GetBitmapNamed(bitmap_id); |
| 443 return tp->GetBitmapNamed(fallback_bitmap_id); | 456 return tp->GetBitmapNamed(fallback_bitmap_id); |
| 444 } | 457 } |
| OLD | NEW |