| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/frame/caption_buttons/maximize_bubble_controller.h" | |
| 6 | |
| 7 #include "ash/frame/caption_buttons/frame_maximize_button.h" | |
| 8 #include "ash/frame/caption_buttons/maximize_bubble_controller_bubble.h" | |
| 9 #include "base/timer/timer.h" | |
| 10 | |
| 11 | |
| 12 namespace ash { | |
| 13 | |
| 14 MaximizeBubbleController::MaximizeBubbleController( | |
| 15 FrameMaximizeButton* frame_maximize_button, | |
| 16 MaximizeBubbleFrameState maximize_type, | |
| 17 int appearance_delay_ms) | |
| 18 : frame_maximize_button_(frame_maximize_button), | |
| 19 bubble_(NULL), | |
| 20 maximize_type_(maximize_type), | |
| 21 snap_type_for_creation_(SNAP_NONE), | |
| 22 appearance_delay_ms_(appearance_delay_ms) { | |
| 23 // Create the task which will create the bubble delayed. | |
| 24 base::OneShotTimer<MaximizeBubbleController>* new_timer = | |
| 25 new base::OneShotTimer<MaximizeBubbleController>(); | |
| 26 // Note: Even if there was no delay time given, we need to have a timer. | |
| 27 new_timer->Start( | |
| 28 FROM_HERE, | |
| 29 base::TimeDelta::FromMilliseconds( | |
| 30 appearance_delay_ms_ ? appearance_delay_ms_ : 10), | |
| 31 this, | |
| 32 &MaximizeBubbleController::CreateBubble); | |
| 33 timer_.reset(new_timer); | |
| 34 if (!appearance_delay_ms_) | |
| 35 CreateBubble(); | |
| 36 } | |
| 37 | |
| 38 MaximizeBubbleController::~MaximizeBubbleController() { | |
| 39 // Note: The destructor only gets initiated through the owner. | |
| 40 timer_.reset(); | |
| 41 if (bubble_) { | |
| 42 bubble_->ControllerRequestsCloseAndDelete(); | |
| 43 bubble_ = NULL; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 void MaximizeBubbleController::SetSnapType(SnapType snap_type) { | |
| 48 if (bubble_) { | |
| 49 bubble_->SetSnapType(snap_type); | |
| 50 } else { | |
| 51 // The bubble has not been created yet. This can occur if bubble creation is | |
| 52 // delayed. | |
| 53 snap_type_for_creation_ = snap_type; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 aura::Window* MaximizeBubbleController::GetBubbleWindow() { | |
| 58 return bubble_ ? bubble_->GetBubbleWindow() : NULL; | |
| 59 } | |
| 60 | |
| 61 void MaximizeBubbleController::DelayCreation() { | |
| 62 if (timer_.get() && timer_->IsRunning()) | |
| 63 timer_->Reset(); | |
| 64 } | |
| 65 | |
| 66 void MaximizeBubbleController::OnButtonClicked(SnapType snap_type) { | |
| 67 frame_maximize_button_->ExecuteSnapAndCloseMenu(snap_type); | |
| 68 } | |
| 69 | |
| 70 void MaximizeBubbleController::OnButtonHover(SnapType snap_type) { | |
| 71 frame_maximize_button_->SnapButtonHovered(snap_type); | |
| 72 } | |
| 73 | |
| 74 views::CustomButton* MaximizeBubbleController::GetButtonForUnitTest( | |
| 75 SnapType state) { | |
| 76 return bubble_ ? bubble_->GetButtonForUnitTest(state) : NULL; | |
| 77 } | |
| 78 | |
| 79 void MaximizeBubbleController::RequestDestructionThroughOwner() { | |
| 80 // Tell the parent to destroy us (if this didn't happen yet). | |
| 81 if (timer_) { | |
| 82 timer_.reset(NULL); | |
| 83 // Informs the owner that the menu is gone and requests |this| destruction. | |
| 84 frame_maximize_button_->DestroyMaximizeMenu(); | |
| 85 // Note: After this call |this| is destroyed. | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 void MaximizeBubbleController::CreateBubble() { | |
| 90 if (!bubble_) { | |
| 91 bubble_ = new MaximizeBubbleControllerBubble(this, appearance_delay_ms_, | |
| 92 snap_type_for_creation_); | |
| 93 frame_maximize_button_->OnMaximizeBubbleShown(bubble_->GetWidget()); | |
| 94 } | |
| 95 | |
| 96 timer_->Stop(); | |
| 97 } | |
| 98 | |
| 99 } // namespace ash | |
| OLD | NEW |