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 27 matching lines...) Expand all Loading... | |
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 explicit ControlView(AppNonClientFrameViewAsh* owner) : | 45 explicit ControlView(AppNonClientFrameViewAsh* owner) : |
46 owner_(owner), | 46 owner_(owner), |
47 close_button_(new views::ImageButton(this)), | 47 close_button_(new views::ImageButton(this)), |
48 restore_button_(new ash::FrameMaximizeButton(this, owner_)) | 48 restore_button_(new ash::FrameMaximizeButton(this, owner_)), |
49 original_maximize_button_width_(0) | |
James Cook
2013/04/22 22:15:46
If we're going to do this mode, I think you should
Mr4D (OOO till 08-26)
2013/04/23 04:41:28
Right. As stated in my CL comment: This was a no g
James Cook
2013/04/23 18:27:32
OK. Keep the button hiding the way you have it, bu
Mr4D (OOO till 08-26)
2013/04/23 22:24:00
Added a TODO(skuhne) comment here to make sure it
| |
49 { | 50 { |
50 close_button_->SetAccessibleName( | 51 close_button_->SetAccessibleName( |
51 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 52 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
52 restore_button_->SetAccessibleName( | 53 restore_button_->SetAccessibleName( |
53 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); | 54 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); |
54 | 55 |
55 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 56 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
56 | 57 |
57 int control_base_resource_id = owner->browser_view()->IsOffTheRecord() ? | 58 int control_base_resource_id = owner->browser_view()->IsOffTheRecord() ? |
58 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : | 59 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : |
59 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; | 60 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; |
60 control_base_ = rb.GetImageNamed(control_base_resource_id).ToImageSkia(); | 61 control_base_ = rb.GetImageNamed(control_base_resource_id).ToImageSkia(); |
61 shadow_ = rb.GetImageNamed( | 62 shadow_ = rb.GetImageNamed( |
62 base::i18n::IsRTL() ? IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL : | 63 base::i18n::IsRTL() ? IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL : |
63 IDR_AURA_WINDOW_FULLSCREEN_SHADOW).ToImageSkia(); | 64 IDR_AURA_WINDOW_FULLSCREEN_SHADOW).ToImageSkia(); |
64 | 65 |
65 AddChildView(close_button_); | 66 AddChildView(close_button_); |
66 AddChildView(restore_button_); | 67 AddChildView(restore_button_); |
67 } | 68 } |
68 | 69 |
69 virtual ~ControlView() {} | 70 virtual ~ControlView() {} |
70 | 71 |
71 virtual void Layout() OVERRIDE { | 72 virtual void Layout() OVERRIDE { |
73 if (ash::Shell::IsForcedMaximizeMode()) { | |
74 // TODO(skuhne): If this experiment would get persued, it would be better | |
75 // to check here the |restore_button_|'s visibility. Furthermore we | |
76 // should change |shadow_| to a new bitmap which can host only a single | |
77 // button. | |
78 gfx::Size size = restore_button_->bounds().size(); | |
79 if (size.width()) { | |
80 original_maximize_button_width_ = size.width(); | |
81 size.set_width(0); | |
82 restore_button_->SetSize(size); | |
83 } | |
84 } | |
72 restore_button_->SetPosition(gfx::Point(kShadowStart, 0)); | 85 restore_button_->SetPosition(gfx::Point(kShadowStart, 0)); |
73 close_button_->SetPosition(gfx::Point(kShadowStart + | 86 close_button_->SetPosition(gfx::Point(kShadowStart + |
74 restore_button_->width() - kButtonOverlap, 0)); | 87 restore_button_->width() - kButtonOverlap, 0)); |
75 } | 88 } |
76 | 89 |
77 virtual void ViewHierarchyChanged(bool is_add, View* parent, | 90 virtual void ViewHierarchyChanged(bool is_add, View* parent, |
78 View* child) OVERRIDE { | 91 View* child) OVERRIDE { |
79 if (is_add && child == this) { | 92 if (is_add && child == this) { |
80 SetButtonImages(restore_button_, | 93 SetButtonImages(restore_button_, |
81 IDR_AURA_WINDOW_FULLSCREEN_RESTORE, | 94 IDR_AURA_WINDOW_FULLSCREEN_RESTORE, |
82 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_H, | 95 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_H, |
83 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_P); | 96 IDR_AURA_WINDOW_FULLSCREEN_RESTORE_P); |
84 restore_button_->SizeToPreferredSize(); | 97 restore_button_->SizeToPreferredSize(); |
85 | 98 |
86 SetButtonImages(close_button_, | 99 SetButtonImages(close_button_, |
87 IDR_AURA_WINDOW_FULLSCREEN_CLOSE, | 100 IDR_AURA_WINDOW_FULLSCREEN_CLOSE, |
88 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_H, | 101 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_H, |
89 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_P); | 102 IDR_AURA_WINDOW_FULLSCREEN_CLOSE_P); |
90 close_button_->SizeToPreferredSize(); | 103 close_button_->SizeToPreferredSize(); |
91 } | 104 } |
92 } | 105 } |
93 | 106 |
94 virtual gfx::Size GetPreferredSize() OVERRIDE { | 107 virtual gfx::Size GetPreferredSize() OVERRIDE { |
95 return gfx::Size(shadow_->width(), | 108 return gfx::Size(shadow_->width() - original_maximize_button_width_, |
96 shadow_->height() + kShadowHeightStretch); | 109 shadow_->height() + kShadowHeightStretch); |
97 } | 110 } |
98 | 111 |
99 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 112 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
100 canvas->TileImageInt(*control_base_, | 113 canvas->TileImageInt(*control_base_, |
101 base::i18n::IsRTL() ? 0 : restore_button_->x(), | 114 base::i18n::IsRTL() ? 0 : restore_button_->x(), |
102 restore_button_->y(), | 115 restore_button_->y(), |
103 restore_button_->width() - kButtonOverlap + close_button_->width(), | 116 restore_button_->width() - kButtonOverlap + close_button_->width(), |
104 restore_button_->height()); | 117 restore_button_->height()); |
105 | 118 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 button->SetImage(views::CustomButton::STATE_PRESSED, | 159 button->SetImage(views::CustomButton::STATE_PRESSED, |
147 theme_provider->GetImageSkiaNamed(pushed_image_id)); | 160 theme_provider->GetImageSkiaNamed(pushed_image_id)); |
148 } | 161 } |
149 | 162 |
150 AppNonClientFrameViewAsh* owner_; | 163 AppNonClientFrameViewAsh* owner_; |
151 views::ImageButton* close_button_; | 164 views::ImageButton* close_button_; |
152 views::ImageButton* restore_button_; | 165 views::ImageButton* restore_button_; |
153 const gfx::ImageSkia* control_base_; | 166 const gfx::ImageSkia* control_base_; |
154 const gfx::ImageSkia* shadow_; | 167 const gfx::ImageSkia* shadow_; |
155 | 168 |
169 // The original size of the maximize button. | |
170 int original_maximize_button_width_; | |
171 | |
156 DISALLOW_COPY_AND_ASSIGN(ControlView); | 172 DISALLOW_COPY_AND_ASSIGN(ControlView); |
157 }; | 173 }; |
158 | 174 |
159 // Observer to detect when the browser frame widget closes so we can clean | 175 // 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 | 176 // up our ControlView. Because we can be closed via a keyboard shortcut we |
161 // are not guaranteed to run AppNonClientFrameView's Close() or Restore(). | 177 // are not guaranteed to run AppNonClientFrameView's Close() or Restore(). |
162 class AppNonClientFrameViewAsh::FrameObserver : public views::WidgetObserver { | 178 class AppNonClientFrameViewAsh::FrameObserver : public views::WidgetObserver { |
163 public: | 179 public: |
164 explicit FrameObserver(AppNonClientFrameViewAsh* owner) : owner_(owner) {} | 180 explicit FrameObserver(AppNonClientFrameViewAsh* owner) : owner_(owner) {} |
165 virtual ~FrameObserver() {} | 181 virtual ~FrameObserver() {} |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, | 295 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, |
280 preferred.width(), preferred.height()); | 296 preferred.width(), preferred.height()); |
281 } | 297 } |
282 | 298 |
283 void AppNonClientFrameViewAsh::CloseControlWidget() { | 299 void AppNonClientFrameViewAsh::CloseControlWidget() { |
284 if (control_widget_) { | 300 if (control_widget_) { |
285 control_widget_->Close(); | 301 control_widget_->Close(); |
286 control_widget_ = NULL; | 302 control_widget_ = NULL; |
287 } | 303 } |
288 } | 304 } |
OLD | NEW |