| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 5 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <map> |
| 8 | 9 |
| 9 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 10 #include "ash/frame/caption_buttons/frame_caption_button.h" | 11 #include "ash/frame/caption_buttons/frame_caption_button.h" |
| 11 #include "ash/frame/caption_buttons/frame_size_button.h" | 12 #include "ash/frame/caption_buttons/frame_size_button.h" |
| 12 #include "ash/metrics/user_metrics_recorder.h" | 13 #include "ash/metrics/user_metrics_recorder.h" |
| 13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 14 #include "grit/ui_strings.h" // Accessibility names | 16 #include "grit/ui_strings.h" // Accessibility names |
| 15 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 19 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 18 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 19 #include "ui/gfx/insets.h" | 21 #include "ui/gfx/insets.h" |
| 20 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
| 21 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 22 #include "ui/views/widget/widget_delegate.h" | 24 #include "ui/views/widget/widget_delegate.h" |
| 23 | 25 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 50 // Insert the buttons left to right. | 52 // Insert the buttons left to right. |
| 51 minimize_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MINIMIZE); | 53 minimize_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_MINIMIZE); |
| 52 minimize_button_->SetAccessibleName( | 54 minimize_button_->SetAccessibleName( |
| 53 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); | 55 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); |
| 54 minimize_button_->SetVisible(minimize_allowed == MINIMIZE_ALLOWED); | 56 minimize_button_->SetVisible(minimize_allowed == MINIMIZE_ALLOWED); |
| 55 AddChildView(minimize_button_); | 57 AddChildView(minimize_button_); |
| 56 | 58 |
| 57 size_button_ = new FrameSizeButton(this, frame, this); | 59 size_button_ = new FrameSizeButton(this, frame, this); |
| 58 size_button_->SetAccessibleName( | 60 size_button_->SetAccessibleName( |
| 59 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); | 61 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); |
| 60 UpdateSizeButtonVisibility(false); | 62 UpdateSizeButtonVisibility(); |
| 61 AddChildView(size_button_); | 63 AddChildView(size_button_); |
| 62 | 64 |
| 63 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE); | 65 close_button_ = new FrameCaptionButton(this, CAPTION_BUTTON_ICON_CLOSE); |
| 64 close_button_->SetAccessibleName( | 66 close_button_->SetAccessibleName( |
| 65 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 67 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
| 66 AddChildView(close_button_); | 68 AddChildView(close_button_); |
| 67 } | 69 } |
| 68 | 70 |
| 69 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() { | 71 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() { |
| 70 } | 72 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } else if (size_button_->visible() && | 114 } else if (size_button_->visible() && |
| 113 ConvertPointToViewAndHitTest(this, size_button_, point)) { | 115 ConvertPointToViewAndHitTest(this, size_button_, point)) { |
| 114 return HTMAXBUTTON; | 116 return HTMAXBUTTON; |
| 115 } else if (minimize_button_->visible() && | 117 } else if (minimize_button_->visible() && |
| 116 ConvertPointToViewAndHitTest(this, minimize_button_, point)) { | 118 ConvertPointToViewAndHitTest(this, minimize_button_, point)) { |
| 117 return HTMINBUTTON; | 119 return HTMINBUTTON; |
| 118 } | 120 } |
| 119 return HTNOWHERE; | 121 return HTNOWHERE; |
| 120 } | 122 } |
| 121 | 123 |
| 122 void FrameCaptionButtonContainerView::UpdateSizeButtonVisibility( | 124 void FrameCaptionButtonContainerView::UpdateSizeButtonVisibility() { |
| 123 bool force_hidden) { | |
| 124 // TODO(flackr): Refactor the Maximize Mode notifications. Currently | |
| 125 // UpdateSizeButtonVisibilty requires a force_hidden parameter. This is | |
| 126 // because Shell::IsMaximizeWindowManagerEnabled is still false at the | |
| 127 // time when ShellObserver::OnMaximizeModeStarted is called. This prevents | |
| 128 // this method from performing that check, and instead relies on the calling | |
| 129 // code to tell it to force being hidden. | |
| 130 size_button_->SetVisible( | 125 size_button_->SetVisible( |
| 131 !force_hidden && frame_->widget_delegate()->CanMaximize()); | 126 !Shell::GetInstance()->maximize_mode_controller()-> |
| 127 IsMaximizeModeWindowManagerEnabled() && |
| 128 frame_->widget_delegate()->CanMaximize()); |
| 132 } | 129 } |
| 133 | 130 |
| 134 gfx::Size FrameCaptionButtonContainerView::GetPreferredSize() const { | 131 gfx::Size FrameCaptionButtonContainerView::GetPreferredSize() const { |
| 135 int width = 0; | 132 int width = 0; |
| 136 for (int i = 0; i < child_count(); ++i) { | 133 for (int i = 0; i < child_count(); ++i) { |
| 137 const views::View* child = child_at(i); | 134 const views::View* child = child_at(i); |
| 138 if (child->visible()) | 135 if (child->visible()) |
| 139 width += child_at(i)->GetPreferredSize().width(); | 136 width += child_at(i)->GetPreferredSize().width(); |
| 140 } | 137 } |
| 141 return gfx::Size(width, close_button_->GetPreferredSize().height()); | 138 return gfx::Size(width, close_button_->GetPreferredSize().height()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 192 } |
| 196 | 193 |
| 197 // Abort any animations of the button icons. | 194 // Abort any animations of the button icons. |
| 198 SetButtonsToNormal(ANIMATE_NO); | 195 SetButtonsToNormal(ANIMATE_NO); |
| 199 | 196 |
| 200 ash::UserMetricsAction action = | 197 ash::UserMetricsAction action = |
| 201 ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE; | 198 ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MINIMIZE; |
| 202 if (sender == minimize_button_) { | 199 if (sender == minimize_button_) { |
| 203 frame_->Minimize(); | 200 frame_->Minimize(); |
| 204 } else if (sender == size_button_) { | 201 } else if (sender == size_button_) { |
| 205 if (frame_->IsFullscreen()) { // Can be clicked in immersive fullscreen. | 202 if (frame_->IsFullscreen()) { // Can be clicked in immersive fullscreen. |
| 206 frame_->SetFullscreen(false); | 203 frame_->SetFullscreen(false); |
| 207 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN; | 204 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_EXIT_FULLSCREEN; |
| 208 } else if (frame_->IsMaximized()) { | 205 } else if (frame_->IsMaximized()) { |
| 209 frame_->Restore(); | 206 frame_->Restore(); |
| 210 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE; | 207 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_RESTORE; |
| 211 } else { | 208 } else { |
| 212 frame_->Maximize(); | 209 frame_->Maximize(); |
| 213 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE; | 210 action = ash::UMA_WINDOW_MAXIMIZE_BUTTON_CLICK_MAXIMIZE; |
| 214 } | 211 } |
| 215 } else if(sender == close_button_) { | 212 } else if (sender == close_button_) { |
| 216 frame_->Close(); | 213 frame_->Close(); |
| 217 action = ash::UMA_WINDOW_CLOSE_BUTTON_CLICK; | 214 action = ash::UMA_WINDOW_CLOSE_BUTTON_CLICK; |
| 218 } else { | 215 } else { |
| 219 return; | 216 return; |
| 220 } | 217 } |
| 221 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(action); | 218 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(action); |
| 222 } | 219 } |
| 223 | 220 |
| 224 bool FrameCaptionButtonContainerView::IsMinimizeButtonVisible() const { | 221 bool FrameCaptionButtonContainerView::IsMinimizeButtonVisible() const { |
| 225 return minimize_button_->visible(); | 222 return minimize_button_->visible(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 : icon_image_id(icon_id), | 301 : icon_image_id(icon_id), |
| 305 inactive_icon_image_id(inactive_icon_id), | 302 inactive_icon_image_id(inactive_icon_id), |
| 306 hovered_background_image_id(hovered_background_id), | 303 hovered_background_image_id(hovered_background_id), |
| 307 pressed_background_image_id(pressed_background_id) { | 304 pressed_background_image_id(pressed_background_id) { |
| 308 } | 305 } |
| 309 | 306 |
| 310 FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() { | 307 FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() { |
| 311 } | 308 } |
| 312 | 309 |
| 313 } // namespace ash | 310 } // namespace ash |
| OLD | NEW |