| 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/app_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/frame/app_non_client_frame_view_ash.h" |
| 6 | 6 |
| 7 #include "ash/shell_delegate.h" | 7 #include "ash/shell_delegate.h" |
| 8 #include "ash/wm/workspace/frame_maximize_button.h" | 8 #include "ash/wm/workspace/frame_maximize_button.h" |
| 9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const int kButtonOverlap = 1; | 35 const int kButtonOverlap = 1; |
| 36 | 36 |
| 37 // TODO(pkotwicz): Remove these constants once the IDR_AURA_FULLSCREEN_SHADOW | 37 // TODO(pkotwicz): Remove these constants once the IDR_AURA_FULLSCREEN_SHADOW |
| 38 // resource is updated. | 38 // resource is updated. |
| 39 const int kShadowHeightStretch = -1; | 39 const int kShadowHeightStretch = -1; |
| 40 } | 40 } |
| 41 | 41 |
| 42 class AppNonClientFrameViewAsh::ControlView | 42 class AppNonClientFrameViewAsh::ControlView |
| 43 : public views::View, public views::ButtonListener { | 43 : public views::View, public views::ButtonListener { |
| 44 public: | 44 public: |
| 45 // TODO(skuhne): If we keep the "always maximized" experiment we might want to |
| 46 // make this function be able to work with a |restore_button_| which is NULL. |
| 45 explicit ControlView(AppNonClientFrameViewAsh* owner) : | 47 explicit ControlView(AppNonClientFrameViewAsh* owner) : |
| 46 owner_(owner), | 48 owner_(owner), |
| 47 close_button_(new views::ImageButton(this)), | 49 close_button_(new views::ImageButton(this)), |
| 48 restore_button_(new ash::FrameMaximizeButton(this, owner_)) | 50 restore_button_(new ash::FrameMaximizeButton(this, owner_)), |
| 51 original_maximize_button_width_(0) |
| 49 { | 52 { |
| 50 close_button_->SetAccessibleName( | 53 close_button_->SetAccessibleName( |
| 51 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 54 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 52 restore_button_->SetAccessibleName( | 55 restore_button_->SetAccessibleName( |
| 53 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); | 56 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); |
| 54 | 57 |
| 55 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 58 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 56 | 59 |
| 57 int control_base_resource_id = owner->browser_view()->IsOffTheRecord() ? | 60 int control_base_resource_id = owner->browser_view()->IsOffTheRecord() ? |
| 58 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : | 61 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : |
| 59 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; | 62 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; |
| 60 control_base_ = rb.GetImageNamed(control_base_resource_id).ToImageSkia(); | 63 control_base_ = rb.GetImageNamed(control_base_resource_id).ToImageSkia(); |
| 61 shadow_ = rb.GetImageNamed( | 64 shadow_ = rb.GetImageNamed( |
| 62 base::i18n::IsRTL() ? IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL : | 65 base::i18n::IsRTL() ? IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL : |
| 63 IDR_AURA_WINDOW_FULLSCREEN_SHADOW).ToImageSkia(); | 66 IDR_AURA_WINDOW_FULLSCREEN_SHADOW).ToImageSkia(); |
| 64 | 67 |
| 65 AddChildView(close_button_); | 68 AddChildView(close_button_); |
| 66 AddChildView(restore_button_); | 69 AddChildView(restore_button_); |
| 67 } | 70 } |
| 68 | 71 |
| 69 virtual ~ControlView() {} | 72 virtual ~ControlView() {} |
| 70 | 73 |
| 71 virtual void Layout() OVERRIDE { | 74 virtual void Layout() OVERRIDE { |
| 75 if (ash::Shell::IsForcedMaximizeMode()) { |
| 76 // TODO(skuhne): If this experiment would get persued, it would be better |
| 77 // to check here the |restore_button_|'s visibility. Furthermore we |
| 78 // should change |shadow_| to a new bitmap which can host only a single |
| 79 // button. |
| 80 gfx::Size size = restore_button_->bounds().size(); |
| 81 if (size.width()) { |
| 82 original_maximize_button_width_ = size.width(); |
| 83 size.set_width(0); |
| 84 restore_button_->SetSize(size); |
| 85 } |
| 86 } |
| 72 restore_button_->SetPosition(gfx::Point(kShadowStart, 0)); | 87 restore_button_->SetPosition(gfx::Point(kShadowStart, 0)); |
| 73 close_button_->SetPosition(gfx::Point(kShadowStart + | 88 close_button_->SetPosition(gfx::Point(kShadowStart + |
| 74 restore_button_->width() - kButtonOverlap, 0)); | 89 restore_button_->width() - kButtonOverlap, 0)); |
| 75 } | 90 } |
| 76 | 91 |
| 77 virtual void ViewHierarchyChanged(bool is_add, View* parent, | 92 virtual void ViewHierarchyChanged(bool is_add, View* parent, |
| 78 View* child) OVERRIDE { | 93 View* child) OVERRIDE { |
| 79 if (is_add && child == this) { | 94 if (is_add && child == this) { |
| 80 SetButtonImages(restore_button_, | 95 SetButtonImages(restore_button_, |
| 81 IDR_AURA_WINDOW_FULLSCREEN_RESTORE, | 96 IDR_AURA_WINDOW_FULLSCREEN_RESTORE, |
| 82 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_H, | 97 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_H, |
| 83 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_P); | 98 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_P); |
| 84 restore_button_->SizeToPreferredSize(); | 99 restore_button_->SizeToPreferredSize(); |
| 85 | 100 |
| 86 SetButtonImages(close_button_, | 101 SetButtonImages(close_button_, |
| 87 IDR_AURA_WINDOW_FULLSCREEN_CLOSE, | 102 IDR_AURA_WINDOW_FULLSCREEN_CLOSE, |
| 88 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_H, | 103 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_H, |
| 89 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_P); | 104 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_P); |
| 90 close_button_->SizeToPreferredSize(); | 105 close_button_->SizeToPreferredSize(); |
| 91 } | 106 } |
| 92 } | 107 } |
| 93 | 108 |
| 94 virtual gfx::Size GetPreferredSize() OVERRIDE { | 109 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 95 return gfx::Size(shadow_->width(), | 110 return gfx::Size(shadow_->width() - original_maximize_button_width_, |
| 96 shadow_->height() + kShadowHeightStretch); | 111 shadow_->height() + kShadowHeightStretch); |
| 97 } | 112 } |
| 98 | 113 |
| 99 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 114 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| 100 canvas->TileImageInt(*control_base_, | 115 canvas->TileImageInt(*control_base_, |
| 101 base::i18n::IsRTL() ? 0 : restore_button_->x(), | 116 base::i18n::IsRTL() ? 0 : restore_button_->x(), |
| 102 restore_button_->y(), | 117 restore_button_->y(), |
| 103 restore_button_->width() - kButtonOverlap + close_button_->width(), | 118 restore_button_->width() - kButtonOverlap + close_button_->width(), |
| 104 restore_button_->height()); | 119 restore_button_->height()); |
| 105 | 120 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 button->SetImage(views::CustomButton::STATE_PRESSED, | 161 button->SetImage(views::CustomButton::STATE_PRESSED, |
| 147 theme_provider->GetImageSkiaNamed(pushed_image_id)); | 162 theme_provider->GetImageSkiaNamed(pushed_image_id)); |
| 148 } | 163 } |
| 149 | 164 |
| 150 AppNonClientFrameViewAsh* owner_; | 165 AppNonClientFrameViewAsh* owner_; |
| 151 views::ImageButton* close_button_; | 166 views::ImageButton* close_button_; |
| 152 views::ImageButton* restore_button_; | 167 views::ImageButton* restore_button_; |
| 153 const gfx::ImageSkia* control_base_; | 168 const gfx::ImageSkia* control_base_; |
| 154 const gfx::ImageSkia* shadow_; | 169 const gfx::ImageSkia* shadow_; |
| 155 | 170 |
| 171 // The original size of the maximize button. |
| 172 int original_maximize_button_width_; |
| 173 |
| 156 DISALLOW_COPY_AND_ASSIGN(ControlView); | 174 DISALLOW_COPY_AND_ASSIGN(ControlView); |
| 157 }; | 175 }; |
| 158 | 176 |
| 159 // Observer to detect when the browser frame widget closes so we can clean | 177 // Observer to detect when the browser frame widget closes so we can clean |
| 160 // up our ControlView. Because we can be closed via a keyboard shortcut we | 178 // up our ControlView. Because we can be closed via a keyboard shortcut we |
| 161 // are not guaranteed to run AppNonClientFrameView's Close() or Restore(). | 179 // are not guaranteed to run AppNonClientFrameView's Close() or Restore(). |
| 162 class AppNonClientFrameViewAsh::FrameObserver : public views::WidgetObserver { | 180 class AppNonClientFrameViewAsh::FrameObserver : public views::WidgetObserver { |
| 163 public: | 181 public: |
| 164 explicit FrameObserver(AppNonClientFrameViewAsh* owner) : owner_(owner) {} | 182 explicit FrameObserver(AppNonClientFrameViewAsh* owner) : owner_(owner) {} |
| 165 virtual ~FrameObserver() {} | 183 virtual ~FrameObserver() {} |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, | 297 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, |
| 280 preferred.width(), preferred.height()); | 298 preferred.width(), preferred.height()); |
| 281 } | 299 } |
| 282 | 300 |
| 283 void AppNonClientFrameViewAsh::CloseControlWidget() { | 301 void AppNonClientFrameViewAsh::CloseControlWidget() { |
| 284 if (control_widget_) { | 302 if (control_widget_) { |
| 285 control_widget_->Close(); | 303 control_widget_->Close(); |
| 286 control_widget_ = NULL; | 304 control_widget_ = NULL; |
| 287 } | 305 } |
| 288 } | 306 } |
| OLD | NEW |