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_)) |
49 { | 51 { |
50 close_button_->SetAccessibleName( | 52 close_button_->SetAccessibleName( |
51 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 53 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
52 restore_button_->SetAccessibleName( | 54 restore_button_->SetAccessibleName( |
53 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); | 55 l10n_util::GetStringUTF16(IDS_ACCNAME_MAXIMIZE)); |
54 | 56 |
55 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 57 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
56 | 58 |
57 int control_base_resource_id = owner->browser_view()->IsOffTheRecord() ? | 59 int control_base_resource_id = owner->browser_view()->IsOffTheRecord() ? |
58 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : | 60 IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : |
59 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; | 61 IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; |
60 control_base_ = rb.GetImageNamed(control_base_resource_id).ToImageSkia(); | 62 control_base_ = rb.GetImageNamed(control_base_resource_id).ToImageSkia(); |
61 shadow_ = rb.GetImageNamed( | 63 shadow_ = rb.GetImageNamed( |
62 base::i18n::IsRTL() ? IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL : | 64 base::i18n::IsRTL() ? IDR_AURA_WINDOW_FULLSCREEN_SHADOW_RTL : |
63 IDR_AURA_WINDOW_FULLSCREEN_SHADOW).ToImageSkia(); | 65 IDR_AURA_WINDOW_FULLSCREEN_SHADOW).ToImageSkia(); |
64 | 66 |
65 AddChildView(close_button_); | 67 AddChildView(close_button_); |
66 AddChildView(restore_button_); | 68 AddChildView(restore_button_); |
67 } | 69 } |
68 | 70 |
69 virtual ~ControlView() {} | 71 virtual ~ControlView() {} |
70 | 72 |
71 virtual void Layout() OVERRIDE { | 73 virtual void Layout() OVERRIDE { |
| 74 if (ash::Shell::IsForcedMaximizeMode()) { |
| 75 // TODO(skuhne): If this experiment would get persued, it would be better |
| 76 // to check here the |restore_button_|'s visibility. Furthermore we |
| 77 // should change |shadow_| to a new bitmap which can host only a single |
| 78 // button. |
| 79 gfx::Size size = restore_button_->bounds().size(); |
| 80 if (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 int maximize_button_deduction = ash::Shell::IsForcedMaximizeMode() ? |
| 109 restore_button_->GetPreferredSize().width() : 0; |
| 110 |
| 111 return gfx::Size(shadow_->width() - maximize_button_deduction, |
96 shadow_->height() + kShadowHeightStretch); | 112 shadow_->height() + kShadowHeightStretch); |
97 } | 113 } |
98 | 114 |
99 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | 115 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
100 canvas->TileImageInt(*control_base_, | 116 canvas->TileImageInt(*control_base_, |
101 base::i18n::IsRTL() ? 0 : restore_button_->x(), | 117 base::i18n::IsRTL() ? 0 : restore_button_->x(), |
102 restore_button_->y(), | 118 restore_button_->y(), |
103 restore_button_->width() - kButtonOverlap + close_button_->width(), | 119 restore_button_->width() - kButtonOverlap + close_button_->width(), |
104 restore_button_->height()); | 120 restore_button_->height()); |
105 | 121 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, | 296 base::i18n::IsRTL() ? 0 : (width() - preferred.width()), 0, |
281 preferred.width(), preferred.height()); | 297 preferred.width(), preferred.height()); |
282 } | 298 } |
283 | 299 |
284 void AppNonClientFrameViewAsh::CloseControlWidget() { | 300 void AppNonClientFrameViewAsh::CloseControlWidget() { |
285 if (control_widget_) { | 301 if (control_widget_) { |
286 control_widget_->Close(); | 302 control_widget_->Close(); |
287 control_widget_ = NULL; | 303 control_widget_ = NULL; |
288 } | 304 } |
289 } | 305 } |
OLD | NEW |