| 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 "ash/wm/workspace/frame_maximize_button.h" | 5 #include "ash/wm/workspace/frame_maximize_button.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
| 8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/maximize_bubble_controller.h" |
| 11 #include "ash/wm/workspace/phantom_window_controller.h" | 12 #include "ash/wm/workspace/phantom_window_controller.h" |
| 12 #include "ash/wm/workspace/snap_sizer.h" | 13 #include "ash/wm/workspace/snap_sizer.h" |
| 13 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
| 14 #include "grit/ui_resources.h" | 15 #include "grit/ui_resources.h" |
| 15 #include "ui/aura/event.h" | 16 #include "ui/aura/event.h" |
| 16 #include "ui/aura/event_filter.h" | 17 #include "ui/aura/event_filter.h" |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 68 |
| 68 FrameMaximizeButton::EscapeEventFilter::~EscapeEventFilter() { | 69 FrameMaximizeButton::EscapeEventFilter::~EscapeEventFilter() { |
| 69 Shell::GetInstance()->RemoveEnvEventFilter(this); | 70 Shell::GetInstance()->RemoveEnvEventFilter(this); |
| 70 } | 71 } |
| 71 | 72 |
| 72 bool FrameMaximizeButton::EscapeEventFilter::PreHandleKeyEvent( | 73 bool FrameMaximizeButton::EscapeEventFilter::PreHandleKeyEvent( |
| 73 aura::Window* target, | 74 aura::Window* target, |
| 74 aura::KeyEvent* event) { | 75 aura::KeyEvent* event) { |
| 75 if (event->type() == ui::ET_KEY_PRESSED && | 76 if (event->type() == ui::ET_KEY_PRESSED && |
| 76 event->key_code() == ui::VKEY_ESCAPE) { | 77 event->key_code() == ui::VKEY_ESCAPE) { |
| 77 button_->Cancel(); | 78 button_->Cancel(false); |
| 78 } | 79 } |
| 79 return false; | 80 return false; |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool FrameMaximizeButton::EscapeEventFilter::PreHandleMouseEvent( | 83 bool FrameMaximizeButton::EscapeEventFilter::PreHandleMouseEvent( |
| 83 aura::Window* target, | 84 aura::Window* target, |
| 84 aura::MouseEvent* event) { | 85 aura::MouseEvent* event) { |
| 85 return false; | 86 return false; |
| 86 } | 87 } |
| 87 | 88 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 98 } | 99 } |
| 99 | 100 |
| 100 // FrameMaximizeButton --------------------------------------------------------- | 101 // FrameMaximizeButton --------------------------------------------------------- |
| 101 | 102 |
| 102 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, | 103 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, |
| 103 views::NonClientFrameView* frame) | 104 views::NonClientFrameView* frame) |
| 104 : ImageButton(listener), | 105 : ImageButton(listener), |
| 105 frame_(frame), | 106 frame_(frame), |
| 106 is_snap_enabled_(false), | 107 is_snap_enabled_(false), |
| 107 exceeded_drag_threshold_(false), | 108 exceeded_drag_threshold_(false), |
| 108 snap_type_(SNAP_NONE) { | 109 window_(NULL), |
| 110 snap_type_(workspace::SNAP_NONE) { |
| 109 // TODO(sky): nuke this. It's temporary while we don't have good images. | 111 // TODO(sky): nuke this. It's temporary while we don't have good images. |
| 110 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); | 112 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); |
| 111 SetTooltipText(l10n_util::GetStringUTF16(IDS_FRAME_MAXIMIZE_BUTTON_TOOLTIP)); | |
| 112 } | 113 } |
| 113 | 114 |
| 114 FrameMaximizeButton::~FrameMaximizeButton() { | 115 FrameMaximizeButton::~FrameMaximizeButton() { |
| 115 } | 116 } |
| 116 | 117 |
| 118 void FrameMaximizeButton::OnWindowBoundsChanged( |
| 119 aura::Window* window, |
| 120 const gfx::Rect& old_bounds, |
| 121 const gfx::Rect& new_bounds) { |
| 122 Cancel(false); |
| 123 } |
| 124 |
| 125 void FrameMaximizeButton::OnWindowDestroying(aura::Window* window) { |
| 126 maximizer_.reset(); |
| 127 if (window_) { |
| 128 CHECK_EQ(window_, window); |
| 129 window_->RemoveObserver(this); |
| 130 window_ = NULL; |
| 131 } |
| 132 } |
| 133 |
| 117 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { | 134 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { |
| 118 is_snap_enabled_ = event.IsLeftMouseButton(); | 135 is_snap_enabled_ = event.IsLeftMouseButton(); |
| 119 if (is_snap_enabled_) | 136 if (is_snap_enabled_) |
| 120 ProcessStartEvent(event); | 137 ProcessStartEvent(event); |
| 121 ImageButton::OnMousePressed(event); | 138 ImageButton::OnMousePressed(event); |
| 122 return true; | 139 return true; |
| 123 } | 140 } |
| 124 | 141 |
| 125 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { | 142 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { |
| 126 ImageButton::OnMouseEntered(event); | 143 ImageButton::OnMouseEntered(event); |
| 144 if (!maximizer_.get()) { |
| 145 DCHECK(parent()->GetWidget()); |
| 146 if (!window_ && parent()) { |
| 147 window_ = parent()->GetWidget()->GetNativeWindow(); |
| 148 window_->AddObserver(this); |
| 149 } |
| 150 maximizer_.reset(new MaximizeBubbleController( |
| 151 this, |
| 152 frame_->GetWidget()->IsMaximized())); |
| 153 } |
| 127 } | 154 } |
| 128 | 155 |
| 129 void FrameMaximizeButton::OnMouseExited(const views::MouseEvent& event) { | 156 void FrameMaximizeButton::OnMouseExited(const views::MouseEvent& event) { |
| 130 ImageButton::OnMouseExited(event); | 157 ImageButton::OnMouseExited(event); |
| 158 // Remove the bubble menu when the button is not pressed and the mouse is not |
| 159 // within the bubble. |
| 160 if (!is_snap_enabled_ && maximizer_.get() && maximizer_->GetBubbleWindow()) { |
| 161 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); |
| 162 if (!maximizer_->GetBubbleWindow()->bounds().Contains(screen_location)) { |
| 163 maximizer_.reset(); |
| 164 // Make sure that all remaining snap hover states get removed. |
| 165 SnapButtonHovered(workspace::SNAP_NONE); |
| 166 } |
| 167 } |
| 131 } | 168 } |
| 132 | 169 |
| 133 bool FrameMaximizeButton::OnMouseDragged(const views::MouseEvent& event) { | 170 bool FrameMaximizeButton::OnMouseDragged(const views::MouseEvent& event) { |
| 134 if (is_snap_enabled_) | 171 if (is_snap_enabled_) |
| 135 ProcessUpdateEvent(event); | 172 ProcessUpdateEvent(event); |
| 136 return ImageButton::OnMouseDragged(event); | 173 return ImageButton::OnMouseDragged(event); |
| 137 } | 174 } |
| 138 | 175 |
| 139 void FrameMaximizeButton::OnMouseReleased(const views::MouseEvent& event) { | 176 void FrameMaximizeButton::OnMouseReleased(const views::MouseEvent& event) { |
| 140 if (!ProcessEndEvent(event)) | 177 if (!ProcessEndEvent(event)) |
| 141 ImageButton::OnMouseReleased(event); | 178 ImageButton::OnMouseReleased(event); |
| 179 maximizer_.reset(); |
| 142 } | 180 } |
| 143 | 181 |
| 144 void FrameMaximizeButton::OnMouseCaptureLost() { | 182 void FrameMaximizeButton::OnMouseCaptureLost() { |
| 145 Cancel(); | 183 Cancel(false); |
| 146 ImageButton::OnMouseCaptureLost(); | 184 ImageButton::OnMouseCaptureLost(); |
| 147 } | 185 } |
| 148 | 186 |
| 149 ui::GestureStatus FrameMaximizeButton::OnGestureEvent( | 187 ui::GestureStatus FrameMaximizeButton::OnGestureEvent( |
| 150 const views::GestureEvent& event) { | 188 const views::GestureEvent& event) { |
| 151 if (event.type() == ui::ET_GESTURE_TAP_DOWN) { | 189 if (event.type() == ui::ET_GESTURE_TAP_DOWN) { |
| 152 is_snap_enabled_ = true; | 190 is_snap_enabled_ = true; |
| 153 ProcessStartEvent(event); | 191 ProcessStartEvent(event); |
| 154 return ui::GESTURE_STATUS_CONSUMED; | 192 return ui::GESTURE_STATUS_CONSUMED; |
| 155 } | 193 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 173 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE || | 211 if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE || |
| 174 event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { | 212 event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
| 175 ProcessUpdateEvent(event); | 213 ProcessUpdateEvent(event); |
| 176 return ui::GESTURE_STATUS_CONSUMED; | 214 return ui::GESTURE_STATUS_CONSUMED; |
| 177 } | 215 } |
| 178 } | 216 } |
| 179 | 217 |
| 180 return ImageButton::OnGestureEvent(event); | 218 return ImageButton::OnGestureEvent(event); |
| 181 } | 219 } |
| 182 | 220 |
| 183 gfx::ImageSkia FrameMaximizeButton::GetImageToPaint() { | 221 void FrameMaximizeButton::SnapButtonHovered(workspace::SnapType type) { |
| 184 if (is_snap_enabled_) { | 222 // Make sure to only show hover operations when no button is pressed and |
| 185 int id = 0; | 223 // a similar snap operation in progress does not get re-applied. |
| 186 if (frame_->GetWidget()->IsMaximized()) { | 224 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_.get())) |
| 187 switch (snap_type_) { | 225 return; |
| 188 case SNAP_LEFT: | 226 // Prime the mouse location with the center of the (local) button. |
| 189 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_LEFT_P; | 227 press_location_ = gfx::Point(width() / 2, height() / 2); |
| 190 break; | 228 // Then get an adjusted mouse position to initiate the effect. |
| 191 case SNAP_RIGHT: | 229 gfx::Point location = press_location_; |
| 192 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_RIGHT_P; | 230 switch (type) { |
| 193 break; | 231 case workspace::SNAP_LEFT: |
| 194 case SNAP_MAXIMIZE: | 232 location.set_x(location.x() - width()); |
| 195 case SNAP_RESTORE: | 233 break; |
| 196 case SNAP_NONE: | 234 case workspace::SNAP_RIGHT: |
| 197 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_P; | 235 location.set_x(location.x() + width()); |
| 198 break; | 236 break; |
| 199 case SNAP_MINIMIZE: | 237 case workspace::SNAP_MINIMIZE: |
| 200 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_MINIMIZE_P; | 238 location.set_y(location.y() + height()); |
| 201 break; | 239 break; |
| 202 default: | 240 case workspace::SNAP_MAXIMIZE: |
| 203 NOTREACHED(); | 241 case workspace::SNAP_RESTORE: |
| 204 } | 242 break; |
| 205 } else { | 243 case workspace::SNAP_NONE: |
| 206 switch (snap_type_) { | 244 Cancel(true); |
| 207 case SNAP_LEFT: | 245 return; |
| 208 id = IDR_AURA_WINDOW_SNAP_LEFT_P; | 246 default: |
| 209 break; | 247 // We should not come here. |
| 210 case SNAP_RIGHT: | 248 NOTREACHED(); |
| 211 id = IDR_AURA_WINDOW_SNAP_RIGHT_P; | |
| 212 break; | |
| 213 case SNAP_MAXIMIZE: | |
| 214 case SNAP_RESTORE: | |
| 215 case SNAP_NONE: | |
| 216 id = IDR_AURA_WINDOW_SNAP_P; | |
| 217 break; | |
| 218 case SNAP_MINIMIZE: | |
| 219 id = IDR_AURA_WINDOW_SNAP_MINIMIZE_P; | |
| 220 break; | |
| 221 default: | |
| 222 NOTREACHED(); | |
| 223 } | |
| 224 } | |
| 225 return *ResourceBundle::GetSharedInstance().GetImageNamed(id).ToImageSkia(); | |
| 226 } | 249 } |
| 227 // Hot and pressed states handled by regular ImageButton. | 250 UpdateSnap(location); |
| 228 return ImageButton::GetImageToPaint(); | 251 } |
| 252 |
| 253 void FrameMaximizeButton::ExecuteSnapAndCloseMenu( |
| 254 workspace::SnapType snap_type) { |
| 255 DCHECK_NE(snap_type_, workspace::SNAP_NONE); |
| 256 snap_type_ = snap_type; |
| 257 Snap(); |
| 258 // Remove any pending snap previews. |
| 259 SnapButtonHovered(workspace::SNAP_NONE); |
| 260 // At this point the operation has been performed and the menu should be |
| 261 // closed - if not, it'll get now closed. |
| 262 maximizer_.reset(); |
| 263 } |
| 264 |
| 265 void FrameMaximizeButton::DestroyMaximizeMenu() { |
| 266 maximizer_.reset(); |
| 229 } | 267 } |
| 230 | 268 |
| 231 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { | 269 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { |
| 232 DCHECK(is_snap_enabled_); | 270 DCHECK(is_snap_enabled_); |
| 271 // Prepare the help menu. |
| 272 if (!maximizer_.get()) { |
| 273 maximizer_.reset(new MaximizeBubbleController( |
| 274 this, |
| 275 frame_->GetWidget()->IsMaximized())); |
| 276 } else { |
| 277 // If the menu did not show up yet, we delay it even a bit more. |
| 278 maximizer_->DelayCreation(); |
| 279 } |
| 233 snap_sizer_.reset(NULL); | 280 snap_sizer_.reset(NULL); |
| 234 InstallEventFilter(); | 281 InstallEventFilter(); |
| 235 snap_type_ = SNAP_NONE; | 282 snap_type_ = workspace::SNAP_NONE; |
| 236 press_location_ = event.location(); | 283 press_location_ = event.location(); |
| 237 exceeded_drag_threshold_ = false; | 284 exceeded_drag_threshold_ = false; |
| 238 update_timer_.Start( | 285 update_timer_.Start( |
| 239 FROM_HERE, | 286 FROM_HERE, |
| 240 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | 287 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
| 241 this, | 288 this, |
| 242 &FrameMaximizeButton::UpdateSnapFromEventLocation); | 289 &FrameMaximizeButton::UpdateSnapFromEventLocation); |
| 243 } | 290 } |
| 244 | 291 |
| 245 void FrameMaximizeButton::ProcessUpdateEvent(const views::LocatedEvent& event) { | 292 void FrameMaximizeButton::ProcessUpdateEvent(const views::LocatedEvent& event) { |
| 246 DCHECK(is_snap_enabled_); | 293 DCHECK(is_snap_enabled_); |
| 247 int delta_x = event.x() - press_location_.x(); | 294 int delta_x = event.x() - press_location_.x(); |
| 248 int delta_y = event.y() - press_location_.y(); | 295 int delta_y = event.y() - press_location_.y(); |
| 249 if (!exceeded_drag_threshold_) { | 296 if (!exceeded_drag_threshold_) { |
| 250 exceeded_drag_threshold_ = | 297 exceeded_drag_threshold_ = |
| 251 views::View::ExceededDragThreshold(delta_x, delta_y); | 298 views::View::ExceededDragThreshold(delta_x, delta_y); |
| 252 } | 299 } |
| 253 if (exceeded_drag_threshold_) | 300 if (exceeded_drag_threshold_) |
| 254 UpdateSnap(event.location()); | 301 UpdateSnap(event.location()); |
| 255 } | 302 } |
| 256 | 303 |
| 257 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { | 304 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { |
| 258 update_timer_.Stop(); | 305 update_timer_.Stop(); |
| 259 UninstallEventFilter(); | 306 UninstallEventFilter(); |
| 260 bool should_snap = is_snap_enabled_; | 307 bool should_snap = is_snap_enabled_; |
| 261 is_snap_enabled_ = false; | 308 is_snap_enabled_ = false; |
| 262 | 309 |
| 263 if (!should_snap || snap_type_ == SNAP_NONE) | 310 // Remove our help menu if the mouse cursor is not still over it. |
| 311 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); |
| 312 if (!GetBoundsInScreen().Contains(screen_location)) |
| 313 maximizer_.reset(); |
| 314 |
| 315 if (!should_snap || snap_type_ == workspace::SNAP_NONE) |
| 264 return false; | 316 return false; |
| 265 | 317 |
| 266 SetState(BS_NORMAL); | 318 SetState(BS_NORMAL); |
| 267 // SetState will not call SchedulePaint() if state was already set to | 319 // SetState will not call SchedulePaint() if state was already set to |
| 268 // BS_NORMAL during a drag. | 320 // BS_NORMAL during a drag. |
| 269 SchedulePaint(); | 321 SchedulePaint(); |
| 270 phantom_window_.reset(); | 322 phantom_window_.reset(); |
| 271 Snap(); | 323 Snap(); |
| 272 return true; | 324 return true; |
| 273 } | 325 } |
| 274 | 326 |
| 275 void FrameMaximizeButton::Cancel() { | 327 void FrameMaximizeButton::Cancel(bool keep_menu_open) { |
| 276 UninstallEventFilter(); | 328 if (!keep_menu_open) { |
| 277 is_snap_enabled_ = false; | 329 maximizer_.reset(); |
| 330 UninstallEventFilter(); |
| 331 is_snap_enabled_ = false; |
| 332 } |
| 278 phantom_window_.reset(); | 333 phantom_window_.reset(); |
| 279 snap_sizer_.reset(); | 334 snap_sizer_.reset(); |
| 335 snap_type_ = workspace::SNAP_NONE; |
| 280 update_timer_.Stop(); | 336 update_timer_.Stop(); |
| 281 SchedulePaint(); | 337 SchedulePaint(); |
| 282 } | 338 } |
| 283 | 339 |
| 284 void FrameMaximizeButton::InstallEventFilter() { | 340 void FrameMaximizeButton::InstallEventFilter() { |
| 285 if (escape_event_filter_.get()) | 341 if (escape_event_filter_.get()) |
| 286 return; | 342 return; |
| 287 | 343 |
| 288 escape_event_filter_.reset(new EscapeEventFilter(this)); | 344 escape_event_filter_.reset(new EscapeEventFilter(this)); |
| 289 } | 345 } |
| 290 | 346 |
| 291 void FrameMaximizeButton::UninstallEventFilter() { | 347 void FrameMaximizeButton::UninstallEventFilter() { |
| 292 escape_event_filter_.reset(NULL); | 348 escape_event_filter_.reset(NULL); |
| 293 } | 349 } |
| 294 | 350 |
| 295 void FrameMaximizeButton::UpdateSnapFromEventLocation() { | 351 void FrameMaximizeButton::UpdateSnapFromEventLocation() { |
| 296 // If the drag threshold has been exceeded the snap location is up to date. | 352 // If the drag threshold has been exceeded the snap location is up to date. |
| 297 if (exceeded_drag_threshold_) | 353 if (exceeded_drag_threshold_) |
| 298 return; | 354 return; |
| 299 exceeded_drag_threshold_ = true; | 355 exceeded_drag_threshold_ = true; |
| 300 UpdateSnap(press_location_); | 356 UpdateSnap(press_location_); |
| 301 } | 357 } |
| 302 | 358 |
| 303 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { | 359 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { |
| 304 SnapType type = SnapTypeForLocation(location); | 360 workspace::SnapType type = SnapTypeForLocation(location); |
| 305 if (type == snap_type_) { | 361 if (type == snap_type_) { |
| 306 if (snap_sizer_.get()) { | 362 if (snap_sizer_.get()) { |
| 307 snap_sizer_->Update(LocationForSnapSizer(location)); | 363 snap_sizer_->Update(LocationForSnapSizer(location)); |
| 308 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( | 364 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( |
| 309 frame_->GetWidget()->GetNativeView()->parent(), | 365 frame_->GetWidget()->GetNativeView()->parent(), |
| 310 snap_sizer_->target_bounds())); | 366 snap_sizer_->target_bounds())); |
| 311 } | 367 } |
| 312 return; | 368 return; |
| 313 } | 369 } |
| 314 | 370 |
| 315 snap_type_ = type; | 371 snap_type_ = type; |
| 316 snap_sizer_.reset(); | 372 snap_sizer_.reset(); |
| 317 SchedulePaint(); | 373 SchedulePaint(); |
| 318 | 374 |
| 319 if (snap_type_ == SNAP_NONE) { | 375 if (snap_type_ == workspace::SNAP_NONE) { |
| 320 phantom_window_.reset(); | 376 phantom_window_.reset(); |
| 321 return; | 377 return; |
| 322 } | 378 } |
| 323 | 379 |
| 324 if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) { | 380 if (snap_type_ == workspace::SNAP_LEFT || |
| 325 SnapSizer::Edge snap_edge = snap_type_ == SNAP_LEFT ? | 381 snap_type_ == workspace::SNAP_RIGHT) { |
| 382 SnapSizer::Edge snap_edge = snap_type_ == workspace::SNAP_LEFT ? |
| 326 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; | 383 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; |
| 327 int grid_size = Shell::GetInstance()->GetGridSize(); | 384 int grid_size = Shell::GetInstance()->GetGridSize(); |
| 328 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), | 385 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), |
| 329 LocationForSnapSizer(location), | 386 LocationForSnapSizer(location), |
| 330 snap_edge, grid_size)); | 387 snap_edge, grid_size)); |
| 331 } | 388 } |
| 332 if (!phantom_window_.get()) { | 389 if (!phantom_window_.get()) { |
| 333 phantom_window_.reset(new internal::PhantomWindowController( | 390 phantom_window_.reset(new internal::PhantomWindowController( |
| 334 frame_->GetWidget()->GetNativeWindow())); | 391 frame_->GetWidget()->GetNativeWindow())); |
| 335 } | 392 } |
| 393 if (maximizer_.get()) { |
| 394 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); |
| 395 maximizer_->SetSnapType(snap_type_); |
| 396 } |
| 336 phantom_window_->Show(ScreenBoundsForType(snap_type_)); | 397 phantom_window_->Show(ScreenBoundsForType(snap_type_)); |
| 337 } | 398 } |
| 338 | 399 |
| 339 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( | 400 workspace::SnapType FrameMaximizeButton::SnapTypeForLocation( |
| 340 const gfx::Point& location) const { | 401 const gfx::Point& location) const { |
| 341 int delta_x = location.x() - press_location_.x(); | 402 int delta_x = location.x() - press_location_.x(); |
| 342 int delta_y = location.y() - press_location_.y(); | 403 int delta_y = location.y() - press_location_.y(); |
| 343 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) | 404 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) |
| 344 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | 405 return !frame_->GetWidget()->IsMaximized() ? workspace::SNAP_MAXIMIZE : |
| 406 workspace::SNAP_RESTORE; |
| 345 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) | 407 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) |
| 346 return SNAP_LEFT; | 408 return workspace::SNAP_LEFT; |
| 347 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) | 409 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) |
| 348 return SNAP_RIGHT; | 410 return workspace::SNAP_RIGHT; |
| 349 else if (delta_y > 0) | 411 else if (delta_y > 0) |
| 350 return SNAP_MINIMIZE; | 412 return workspace::SNAP_MINIMIZE; |
| 351 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | 413 return !frame_->GetWidget()->IsMaximized() ? workspace::SNAP_MAXIMIZE : |
| 414 workspace::SNAP_RESTORE; |
| 352 } | 415 } |
| 353 | 416 |
| 354 gfx::Rect FrameMaximizeButton::ScreenBoundsForType(SnapType type) const { | 417 gfx::Rect FrameMaximizeButton::ScreenBoundsForType( |
| 418 workspace::SnapType type) const { |
| 355 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); | 419 aura::Window* window = frame_->GetWidget()->GetNativeWindow(); |
| 356 switch (type) { | 420 switch (type) { |
| 357 case SNAP_LEFT: | 421 case workspace::SNAP_LEFT: |
| 358 case SNAP_RIGHT: | 422 case workspace::SNAP_RIGHT: |
| 359 return ScreenAsh::ConvertRectToScreen( | 423 return ScreenAsh::ConvertRectToScreen( |
| 360 frame_->GetWidget()->GetNativeView()->parent(), | 424 frame_->GetWidget()->GetNativeView()->parent(), |
| 361 snap_sizer_->target_bounds()); | 425 snap_sizer_->target_bounds()); |
| 362 case SNAP_MAXIMIZE: | 426 case workspace::SNAP_MAXIMIZE: |
| 363 return ScreenAsh::ConvertRectToScreen( | 427 return ScreenAsh::ConvertRectToScreen( |
| 364 window->parent(), | 428 window->parent(), |
| 365 ScreenAsh::GetMaximizedWindowBoundsInParent(window)); | 429 ScreenAsh::GetMaximizedWindowBoundsInParent(window)); |
| 366 case SNAP_MINIMIZE: { | 430 case workspace::SNAP_MINIMIZE: { |
| 367 Launcher* launcher = Shell::GetInstance()->launcher(); | 431 Launcher* launcher = Shell::GetInstance()->launcher(); |
| 368 gfx::Rect item_rect(launcher->GetScreenBoundsOfItemIconForWindow(window)); | 432 gfx::Rect item_rect(launcher->GetScreenBoundsOfItemIconForWindow(window)); |
| 369 if (!item_rect.IsEmpty()) { | 433 if (!item_rect.IsEmpty()) { |
| 370 // PhantomWindowController insets slightly, outset it so the phantom | 434 // PhantomWindowController insets slightly, outset it so the phantom |
| 371 // doesn't appear inset. | 435 // doesn't appear inset. |
| 372 item_rect.Inset(-8, -8); | 436 item_rect.Inset(-8, -8); |
| 373 return item_rect; | 437 return item_rect; |
| 374 } | 438 } |
| 375 return launcher->widget()->GetWindowBoundsInScreen(); | 439 return launcher->widget()->GetWindowBoundsInScreen(); |
| 376 } | 440 } |
| 377 case SNAP_RESTORE: { | 441 case workspace::SNAP_RESTORE: { |
| 378 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); | 442 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); |
| 379 return restore ? | 443 return restore ? |
| 380 *restore : frame_->GetWidget()->GetWindowBoundsInScreen(); | 444 *restore : frame_->GetWidget()->GetWindowBoundsInScreen(); |
| 381 } | 445 } |
| 382 case SNAP_NONE: | 446 case workspace::SNAP_NONE: |
| 383 NOTREACHED(); | 447 NOTREACHED(); |
| 384 } | 448 } |
| 385 return gfx::Rect(); | 449 return gfx::Rect(); |
| 386 } | 450 } |
| 387 | 451 |
| 388 gfx::Point FrameMaximizeButton::LocationForSnapSizer( | 452 gfx::Point FrameMaximizeButton::LocationForSnapSizer( |
| 389 const gfx::Point& location) const { | 453 const gfx::Point& location) const { |
| 390 gfx::Point result(location); | 454 gfx::Point result(location); |
| 391 views::View::ConvertPointToScreen(this, &result); | 455 views::View::ConvertPointToScreen(this, &result); |
| 392 return result; | 456 return result; |
| 393 } | 457 } |
| 394 | 458 |
| 395 void FrameMaximizeButton::Snap() { | 459 void FrameMaximizeButton::Snap() { |
| 396 switch (snap_type_) { | 460 switch (snap_type_) { |
| 397 case SNAP_LEFT: | 461 case workspace::SNAP_LEFT: |
| 398 case SNAP_RIGHT: | 462 case workspace::SNAP_RIGHT: |
| 399 if (frame_->GetWidget()->IsMaximized()) { | 463 if (frame_->GetWidget()->IsMaximized()) { |
| 400 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), | 464 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), |
| 401 ScreenBoundsForType(snap_type_)); | 465 ScreenBoundsForType(snap_type_)); |
| 402 frame_->GetWidget()->Restore(); | 466 frame_->GetWidget()->Restore(); |
| 403 } else { | 467 } else { |
| 404 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); | 468 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); |
| 405 } | 469 } |
| 406 break; | 470 break; |
| 407 case SNAP_MAXIMIZE: | 471 case workspace::SNAP_MAXIMIZE: |
| 408 frame_->GetWidget()->Maximize(); | 472 frame_->GetWidget()->Maximize(); |
| 409 break; | 473 break; |
| 410 case SNAP_MINIMIZE: | 474 case workspace::SNAP_MINIMIZE: |
| 411 frame_->GetWidget()->Minimize(); | 475 frame_->GetWidget()->Minimize(); |
| 412 break; | 476 break; |
| 413 case SNAP_RESTORE: | 477 case workspace::SNAP_RESTORE: |
| 414 frame_->GetWidget()->Restore(); | 478 frame_->GetWidget()->Restore(); |
| 415 break; | 479 break; |
| 416 case SNAP_NONE: | 480 case workspace::SNAP_NONE: |
| 417 NOTREACHED(); | 481 NOTREACHED(); |
| 418 } | 482 } |
| 419 } | 483 } |
| 420 | 484 |
| 421 } // namespace ash | 485 } // namespace ash |
| OLD | NEW |