| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_size_button.h" | 5 #include "ash/common/frame/caption_buttons/frame_size_button.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | |
| 8 #include "ash/common/wm/window_positioning_utils.h" | 7 #include "ash/common/wm/window_positioning_utils.h" |
| 9 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
| 10 #include "ash/common/wm/wm_event.h" | 9 #include "ash/common/wm/wm_event.h" |
| 11 #include "ash/common/wm/workspace/phantom_window_controller.h" | 10 #include "ash/common/wm/workspace/phantom_window_controller.h" |
| 11 #include "ash/common/wm_lookup.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/screen_util.h" | 13 #include "ash/common/wm_window.h" |
| 14 #include "ash/wm/window_state_aura.h" | |
| 15 #include "ash/wm/window_util.h" | |
| 16 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 17 #include "ui/aura/window.h" | |
| 18 #include "ui/gfx/geometry/vector2d.h" | 15 #include "ui/gfx/geometry/vector2d.h" |
| 19 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 20 | 17 |
| 21 namespace ash { | 18 namespace ash { |
| 22 | 19 |
| 23 namespace { | 20 namespace { |
| 24 | 21 |
| 25 // The default delay between the user pressing the size button and the buttons | 22 // The default delay between the user pressing the size button and the buttons |
| 26 // adjacent to the size button morphing into buttons for snapping left and | 23 // adjacent to the size button morphing into buttons for snapping left and |
| 27 // right. | 24 // right. |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 case CAPTION_BUTTON_ICON_CLOSE: | 204 case CAPTION_BUTTON_ICON_CLOSE: |
| 208 case CAPTION_BUTTON_ICON_BACK: | 205 case CAPTION_BUTTON_ICON_BACK: |
| 209 case CAPTION_BUTTON_ICON_LOCATION: | 206 case CAPTION_BUTTON_ICON_LOCATION: |
| 210 case CAPTION_BUTTON_ICON_COUNT: | 207 case CAPTION_BUTTON_ICON_COUNT: |
| 211 NOTREACHED(); | 208 NOTREACHED(); |
| 212 break; | 209 break; |
| 213 } | 210 } |
| 214 } | 211 } |
| 215 | 212 |
| 216 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { | 213 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { |
| 217 aura::Window* window = frame_->GetNativeWindow(); | 214 WmWindow* window = WmLookup::Get()->GetWindowForWidget(frame_); |
| 218 if (!phantom_window_controller_.get()) { | 215 if (!phantom_window_controller_.get()) |
| 219 phantom_window_controller_.reset( | 216 phantom_window_controller_.reset(new PhantomWindowController(window)); |
| 220 new PhantomWindowController(WmWindowAura::Get(window))); | |
| 221 } | |
| 222 gfx::Rect phantom_bounds_in_parent = | 217 gfx::Rect phantom_bounds_in_parent = |
| 223 (snap_type_ == SNAP_LEFT) | 218 (snap_type_ == SNAP_LEFT) |
| 224 ? wm::GetDefaultLeftSnappedWindowBoundsInParent( | 219 ? wm::GetDefaultLeftSnappedWindowBoundsInParent(window) |
| 225 WmWindowAura::Get(window)) | 220 : wm::GetDefaultRightSnappedWindowBoundsInParent(window); |
| 226 : wm::GetDefaultRightSnappedWindowBoundsInParent( | 221 phantom_window_controller_->Show( |
| 227 WmWindowAura::Get(window)); | 222 window->GetParent()->ConvertRectToScreen(phantom_bounds_in_parent)); |
| 228 phantom_window_controller_->Show(ScreenUtil::ConvertRectToScreen( | |
| 229 window->parent(), phantom_bounds_in_parent)); | |
| 230 } else { | 223 } else { |
| 231 phantom_window_controller_.reset(); | 224 phantom_window_controller_.reset(); |
| 232 } | 225 } |
| 233 } | 226 } |
| 234 | 227 |
| 235 const FrameCaptionButton* FrameSizeButton::GetButtonToHover( | 228 const FrameCaptionButton* FrameSizeButton::GetButtonToHover( |
| 236 const gfx::Point& event_location_in_screen) const { | 229 const gfx::Point& event_location_in_screen) const { |
| 237 const FrameCaptionButton* closest_button = | 230 const FrameCaptionButton* closest_button = |
| 238 delegate_->GetButtonClosestTo(event_location_in_screen); | 231 delegate_->GetButtonClosestTo(event_location_in_screen); |
| 239 if ((closest_button->icon() == CAPTION_BUTTON_ICON_LEFT_SNAPPED || | 232 if ((closest_button->icon() == CAPTION_BUTTON_ICON_LEFT_SNAPPED || |
| 240 closest_button->icon() == CAPTION_BUTTON_ICON_RIGHT_SNAPPED) && | 233 closest_button->icon() == CAPTION_BUTTON_ICON_RIGHT_SNAPPED) && |
| 241 HitTestButton(closest_button, event_location_in_screen)) { | 234 HitTestButton(closest_button, event_location_in_screen)) { |
| 242 return closest_button; | 235 return closest_button; |
| 243 } | 236 } |
| 244 return NULL; | 237 return NULL; |
| 245 } | 238 } |
| 246 | 239 |
| 247 bool FrameSizeButton::CommitSnap(const ui::LocatedEvent& event) { | 240 bool FrameSizeButton::CommitSnap(const ui::LocatedEvent& event) { |
| 248 // The position of |event| may be different than the position of the previous | 241 // The position of |event| may be different than the position of the previous |
| 249 // event. | 242 // event. |
| 250 UpdateSnapType(event); | 243 UpdateSnapType(event); |
| 251 | 244 |
| 252 if (in_snap_mode_ && (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { | 245 if (in_snap_mode_ && (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { |
| 253 wm::WindowState* window_state = | 246 WmWindow* window = WmLookup::Get()->GetWindowForWidget(frame_); |
| 254 wm::GetWindowState(frame_->GetNativeWindow()); | 247 wm::WindowState* window_state = window->GetWindowState(); |
| 255 const wm::WMEvent snap_event(snap_type_ == SNAP_LEFT | 248 const wm::WMEvent snap_event(snap_type_ == SNAP_LEFT |
| 256 ? wm::WM_EVENT_SNAP_LEFT | 249 ? wm::WM_EVENT_SNAP_LEFT |
| 257 : wm::WM_EVENT_SNAP_RIGHT); | 250 : wm::WM_EVENT_SNAP_RIGHT); |
| 258 window_state->OnWMEvent(&snap_event); | 251 window_state->OnWMEvent(&snap_event); |
| 259 WmShell::Get()->RecordUserMetricsAction( | 252 WmShell::Get()->RecordUserMetricsAction( |
| 260 snap_type_ == SNAP_LEFT ? UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT | 253 snap_type_ == SNAP_LEFT ? UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT |
| 261 : UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); | 254 : UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); |
| 262 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_NO); | 255 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_NO); |
| 263 return true; | 256 return true; |
| 264 } | 257 } |
| 265 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_YES); | 258 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_YES); |
| 266 return false; | 259 return false; |
| 267 } | 260 } |
| 268 | 261 |
| 269 void FrameSizeButton::SetButtonsToNormalMode( | 262 void FrameSizeButton::SetButtonsToNormalMode( |
| 270 FrameSizeButtonDelegate::Animate animate) { | 263 FrameSizeButtonDelegate::Animate animate) { |
| 271 in_snap_mode_ = false; | 264 in_snap_mode_ = false; |
| 272 snap_type_ = SNAP_NONE; | 265 snap_type_ = SNAP_NONE; |
| 273 set_buttons_to_snap_mode_timer_.Stop(); | 266 set_buttons_to_snap_mode_timer_.Stop(); |
| 274 delegate_->SetButtonsToNormal(animate); | 267 delegate_->SetButtonsToNormal(animate); |
| 275 phantom_window_controller_.reset(); | 268 phantom_window_controller_.reset(); |
| 276 } | 269 } |
| 277 | 270 |
| 278 } // namespace ash | 271 } // namespace ash |
| OLD | NEW |