| 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 #include <map> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 AddChildView(close_button_); | 142 AddChildView(close_button_); |
| 143 } | 143 } |
| 144 | 144 |
| 145 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() { | 145 FrameCaptionButtonContainerView::~FrameCaptionButtonContainerView() { |
| 146 } | 146 } |
| 147 | 147 |
| 148 void FrameCaptionButtonContainerView::TestApi::EndAnimations() { | 148 void FrameCaptionButtonContainerView::TestApi::EndAnimations() { |
| 149 container_view_->maximize_mode_animation_->End(); | 149 container_view_->maximize_mode_animation_->End(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void FrameCaptionButtonContainerView::SetButtonImages( | 152 void FrameCaptionButtonContainerView::SetButtonImage(CaptionButtonIcon icon, |
| 153 CaptionButtonIcon icon, | 153 int icon_image_id) { |
| 154 int icon_image_id, | 154 button_icon_id_map_[icon] = icon_image_id; |
| 155 int hovered_background_image_id, | 155 |
| 156 int pressed_background_image_id) { | |
| 157 button_icon_id_map_[icon] = ButtonIconIds(icon_image_id, | |
| 158 hovered_background_image_id, | |
| 159 pressed_background_image_id); | |
| 160 FrameCaptionButton* buttons[] = { | 156 FrameCaptionButton* buttons[] = { |
| 161 minimize_button_, size_button_, close_button_ | 157 minimize_button_, size_button_, close_button_ |
| 162 }; | 158 }; |
| 163 for (size_t i = 0; i < arraysize(buttons); ++i) { | 159 for (size_t i = 0; i < arraysize(buttons); ++i) { |
| 164 if (buttons[i]->icon() == icon) { | 160 if (buttons[i]->icon() == icon) |
| 165 buttons[i]->SetImages(icon, | 161 buttons[i]->SetImage(icon, FrameCaptionButton::ANIMATE_NO, icon_image_id); |
| 166 FrameCaptionButton::ANIMATE_NO, | |
| 167 icon_image_id, | |
| 168 hovered_background_image_id, | |
| 169 pressed_background_image_id); | |
| 170 } | |
| 171 } | 162 } |
| 172 } | 163 } |
| 173 | 164 |
| 174 void FrameCaptionButtonContainerView::SetPaintAsActive(bool paint_as_active) { | 165 void FrameCaptionButtonContainerView::SetPaintAsActive(bool paint_as_active) { |
| 175 minimize_button_->set_paint_as_active(paint_as_active); | 166 minimize_button_->set_paint_as_active(paint_as_active); |
| 176 size_button_->set_paint_as_active(paint_as_active); | 167 size_button_->set_paint_as_active(paint_as_active); |
| 177 close_button_->set_paint_as_active(paint_as_active); | 168 close_button_->set_paint_as_active(paint_as_active); |
| 178 } | 169 } |
| 179 | 170 |
| 180 void FrameCaptionButtonContainerView::ResetWindowControls() { | 171 void FrameCaptionButtonContainerView::ResetWindowControls() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 201 if (visible) { | 192 if (visible) { |
| 202 size_button_->SetVisible(true); | 193 size_button_->SetVisible(true); |
| 203 maximize_mode_animation_->SetSlideDuration(kShowAnimationDurationMs); | 194 maximize_mode_animation_->SetSlideDuration(kShowAnimationDurationMs); |
| 204 maximize_mode_animation_->Show(); | 195 maximize_mode_animation_->Show(); |
| 205 } else { | 196 } else { |
| 206 maximize_mode_animation_->SetSlideDuration(kHideAnimationDurationMs); | 197 maximize_mode_animation_->SetSlideDuration(kHideAnimationDurationMs); |
| 207 maximize_mode_animation_->Hide(); | 198 maximize_mode_animation_->Hide(); |
| 208 } | 199 } |
| 209 } | 200 } |
| 210 | 201 |
| 202 void FrameCaptionButtonContainerView::SetButtonSize(const gfx::Size& size) { |
| 203 minimize_button_->set_size(size); |
| 204 size_button_->set_size(size); |
| 205 close_button_->set_size(size); |
| 206 } |
| 207 |
| 211 gfx::Size FrameCaptionButtonContainerView::GetPreferredSize() const { | 208 gfx::Size FrameCaptionButtonContainerView::GetPreferredSize() const { |
| 212 int width = 0; | 209 int width = 0; |
| 213 for (int i = 0; i < child_count(); ++i) { | 210 for (int i = 0; i < child_count(); ++i) { |
| 214 const views::View* child = child_at(i); | 211 const views::View* child = child_at(i); |
| 215 if (child->visible()) | 212 if (child->visible()) |
| 216 width += child_at(i)->GetPreferredSize().width(); | 213 width += child_at(i)->GetPreferredSize().width(); |
| 217 } | 214 } |
| 218 return gfx::Size(width, close_button_->GetPreferredSize().height()); | 215 return gfx::Size(width, close_button_->GetPreferredSize().height()); |
| 219 } | 216 } |
| 220 | 217 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 // The early return is dependant on |animate| because callers use | 289 // The early return is dependant on |animate| because callers use |
| 293 // SetButtonIcon() with ANIMATE_NO to progress |button|'s crossfade animation | 290 // SetButtonIcon() with ANIMATE_NO to progress |button|'s crossfade animation |
| 294 // to the end. | 291 // to the end. |
| 295 if (button->icon() == icon && | 292 if (button->icon() == icon && |
| 296 (animate == ANIMATE_YES || !button->IsAnimatingImageSwap())) { | 293 (animate == ANIMATE_YES || !button->IsAnimatingImageSwap())) { |
| 297 return; | 294 return; |
| 298 } | 295 } |
| 299 | 296 |
| 300 FrameCaptionButton::Animate fcb_animate = (animate == ANIMATE_YES) ? | 297 FrameCaptionButton::Animate fcb_animate = (animate == ANIMATE_YES) ? |
| 301 FrameCaptionButton::ANIMATE_YES : FrameCaptionButton::ANIMATE_NO; | 298 FrameCaptionButton::ANIMATE_YES : FrameCaptionButton::ANIMATE_NO; |
| 302 std::map<CaptionButtonIcon, ButtonIconIds>::const_iterator it = | 299 auto it = button_icon_id_map_.find(icon); |
| 303 button_icon_id_map_.find(icon); | 300 if (it != button_icon_id_map_.end()) |
| 304 if (it != button_icon_id_map_.end()) { | 301 button->SetImage(icon, fcb_animate, it->second); |
| 305 button->SetImages(icon, | |
| 306 fcb_animate, | |
| 307 it->second.icon_image_id, | |
| 308 it->second.hovered_background_image_id, | |
| 309 it->second.pressed_background_image_id); | |
| 310 } | |
| 311 } | 302 } |
| 312 | 303 |
| 313 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const { | 304 bool FrameCaptionButtonContainerView::ShouldSizeButtonBeVisible() const { |
| 314 return !Shell::GetInstance()->maximize_mode_controller()-> | 305 return !Shell::GetInstance()->maximize_mode_controller()-> |
| 315 IsMaximizeModeWindowManagerEnabled() && | 306 IsMaximizeModeWindowManagerEnabled() && |
| 316 frame_->widget_delegate()->CanMaximize(); | 307 frame_->widget_delegate()->CanMaximize(); |
| 317 } | 308 } |
| 318 | 309 |
| 319 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender, | 310 void FrameCaptionButtonContainerView::ButtonPressed(views::Button* sender, |
| 320 const ui::Event& event) { | 311 const ui::Event& event) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 FrameCaptionButton* button = buttons[i]; | 402 FrameCaptionButton* button = buttons[i]; |
| 412 views::Button::ButtonState new_state = views::Button::STATE_NORMAL; | 403 views::Button::ButtonState new_state = views::Button::STATE_NORMAL; |
| 413 if (button == to_hover) | 404 if (button == to_hover) |
| 414 new_state = views::Button::STATE_HOVERED; | 405 new_state = views::Button::STATE_HOVERED; |
| 415 else if (button == to_press) | 406 else if (button == to_press) |
| 416 new_state = views::Button::STATE_PRESSED; | 407 new_state = views::Button::STATE_PRESSED; |
| 417 button->SetState(new_state); | 408 button->SetState(new_state); |
| 418 } | 409 } |
| 419 } | 410 } |
| 420 | 411 |
| 421 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds() | |
| 422 : icon_image_id(-1), | |
| 423 hovered_background_image_id(-1), | |
| 424 pressed_background_image_id(-1) { | |
| 425 } | |
| 426 | |
| 427 FrameCaptionButtonContainerView::ButtonIconIds::ButtonIconIds( | |
| 428 int icon_id, | |
| 429 int hovered_background_id, | |
| 430 int pressed_background_id) | |
| 431 : icon_image_id(icon_id), | |
| 432 hovered_background_image_id(hovered_background_id), | |
| 433 pressed_background_image_id(pressed_background_id) { | |
| 434 } | |
| 435 | |
| 436 FrameCaptionButtonContainerView::ButtonIconIds::~ButtonIconIds() { | |
| 437 } | |
| 438 | |
| 439 } // namespace ash | 412 } // namespace ash |
| OLD | NEW |