Chromium Code Reviews| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after 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_(SNAP_NONE), | |
| 111 maximizer_(NULL) { | |
|
sky
2012/08/02 18:30:30
no need for this.
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 109 // TODO(sky): nuke this. It's temporary while we don't have good images. | 112 // TODO(sky): nuke this. It's temporary while we don't have good images. |
| 110 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); | 113 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); |
| 111 SetTooltipText(l10n_util::GetStringUTF16(IDS_FRAME_MAXIMIZE_BUTTON_TOOLTIP)); | |
| 112 } | 114 } |
| 113 | 115 |
| 114 FrameMaximizeButton::~FrameMaximizeButton() { | 116 FrameMaximizeButton::~FrameMaximizeButton() { |
| 115 } | 117 } |
| 116 | 118 |
| 119 void FrameMaximizeButton::OnWindowBoundsChanged( | |
| 120 aura::Window* window, | |
| 121 const gfx::Rect& old_bounds, | |
| 122 const gfx::Rect& new_bounds) { | |
| 123 Cancel(); | |
| 124 } | |
| 125 | |
| 126 void FrameMaximizeButton::OnWindowDestroying(aura::Window* window) { | |
| 127 maximizer_.reset(); | |
| 128 if (window_) { | |
| 129 CHECK_EQ(window_, window); | |
| 130 window_->RemoveObserver(this); | |
| 131 window_ = NULL; | |
| 132 } | |
| 133 } | |
| 134 | |
| 117 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { | 135 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { |
| 118 is_snap_enabled_ = event.IsLeftMouseButton(); | 136 is_snap_enabled_ = event.IsLeftMouseButton(); |
| 119 if (is_snap_enabled_) | 137 if (is_snap_enabled_) |
| 120 ProcessStartEvent(event); | 138 ProcessStartEvent(event); |
| 121 ImageButton::OnMousePressed(event); | 139 ImageButton::OnMousePressed(event); |
| 122 return true; | 140 return true; |
| 123 } | 141 } |
| 124 | 142 |
| 125 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { | 143 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { |
| 126 ImageButton::OnMouseEntered(event); | 144 ImageButton::OnMouseEntered(event); |
| 145 if (!maximizer_.get()) { | |
| 146 if (!window_ && parent() && parent()->GetWidget()) { | |
|
sky
2012/08/02 18:30:30
I think GetWidget() should be a DCHECK here (espec
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 147 window_ = parent()->GetWidget()->GetNativeWindow(); | |
| 148 window_->AddObserver(this); | |
| 149 } | |
| 150 maximizer_.reset(new MaximizeBubbleController( | |
| 151 this, | |
| 152 frame_->GetWidget()->IsMaximized())); | |
|
sky
2012/08/02 18:30:30
This should be consistent with 146/147.
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Ok
| |
| 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_->GetMenuWindow()) { | |
| 161 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); | |
|
sky
2012/08/02 18:30:30
The event has a location, can't you use it?
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
First off: I am using the mouse coordinate here an
| |
| 162 if (!maximizer_->GetMenuWindow()->bounds().Contains(screen_location)) { | |
| 163 maximizer_.reset(); | |
| 164 // Make sure that all remaining snap hover states get removed. | |
| 165 SnapButtonHovered(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(); |
| 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) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 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 gfx::ImageSkia FrameMaximizeButton::GetImageToPaint() { |
| 184 if (is_snap_enabled_) { | 222 if (is_snap_enabled_) { |
| 185 int id = 0; | 223 int id = 0; |
| 186 if (frame_->GetWidget()->IsMaximized()) { | 224 if (frame_->GetWidget()->IsMaximized()) { |
| 187 switch (snap_type_) { | 225 // TODO(SKUHNE): Remove old bitmaps as soon as the final artwork comes in: |
| 188 case SNAP_LEFT: | 226 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_LEFT_P |
| 189 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_LEFT_P; | 227 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_RIGHT_P |
| 190 break; | 228 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_MINIMIZE_P |
| 191 case SNAP_RIGHT: | 229 // IDR_AURA_WINDOW_SNAP_LEFT_P |
| 192 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_RIGHT_P; | 230 // IDR_AURA_WINDOW_SNAP_RIGHT_P |
| 193 break; | 231 // IDR_AURA_WINDOW_SNAP_MINIMIZE_P |
| 194 case SNAP_MAXIMIZE: | 232 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_P; |
| 195 case SNAP_RESTORE: | 233 } else |
| 196 case SNAP_NONE: | 234 id = IDR_AURA_WINDOW_SNAP_P; |
| 197 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_P; | |
| 198 break; | |
| 199 case SNAP_MINIMIZE: | |
| 200 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_MINIMIZE_P; | |
| 201 break; | |
| 202 default: | |
| 203 NOTREACHED(); | |
| 204 } | |
| 205 } else { | |
| 206 switch (snap_type_) { | |
| 207 case SNAP_LEFT: | |
| 208 id = IDR_AURA_WINDOW_SNAP_LEFT_P; | |
| 209 break; | |
| 210 case SNAP_RIGHT: | |
| 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(); | 235 return *ResourceBundle::GetSharedInstance().GetImageNamed(id).ToImageSkia(); |
| 226 } | 236 } |
| 227 // Hot and pressed states handled by regular ImageButton. | 237 // Hot and pressed states handled by regular ImageButton. |
| 228 return ImageButton::GetImageToPaint(); | 238 return ImageButton::GetImageToPaint(); |
| 229 } | 239 } |
| 230 | 240 |
| 231 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { | 241 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { |
| 232 DCHECK(is_snap_enabled_); | 242 DCHECK(is_snap_enabled_); |
| 243 // Prepare the help / halo menu. | |
|
msw
2012/08/02 18:56:59
nit: what's " help / halo"? Update comment.
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 244 if (!maximizer_.get()) { | |
| 245 maximizer_.reset(new MaximizeBubbleController( | |
| 246 this, | |
| 247 frame_->GetWidget()->IsMaximized())); | |
| 248 } else { | |
| 249 // If the menu did not show up yet, we delay it even a bit more. | |
| 250 maximizer_->DelayCreation(); | |
| 251 } | |
| 233 snap_sizer_.reset(NULL); | 252 snap_sizer_.reset(NULL); |
| 234 InstallEventFilter(); | 253 InstallEventFilter(); |
| 235 snap_type_ = SNAP_NONE; | 254 snap_type_ = SNAP_NONE; |
| 236 press_location_ = event.location(); | 255 press_location_ = event.location(); |
| 237 exceeded_drag_threshold_ = false; | 256 exceeded_drag_threshold_ = false; |
| 238 update_timer_.Start( | 257 update_timer_.Start( |
| 239 FROM_HERE, | 258 FROM_HERE, |
| 240 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | 259 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
| 241 this, | 260 this, |
| 242 &FrameMaximizeButton::UpdateSnapFromEventLocation); | 261 &FrameMaximizeButton::UpdateSnapFromEventLocation); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 253 if (exceeded_drag_threshold_) | 272 if (exceeded_drag_threshold_) |
| 254 UpdateSnap(event.location()); | 273 UpdateSnap(event.location()); |
| 255 } | 274 } |
| 256 | 275 |
| 257 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { | 276 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { |
| 258 update_timer_.Stop(); | 277 update_timer_.Stop(); |
| 259 UninstallEventFilter(); | 278 UninstallEventFilter(); |
| 260 bool should_snap = is_snap_enabled_; | 279 bool should_snap = is_snap_enabled_; |
| 261 is_snap_enabled_ = false; | 280 is_snap_enabled_ = false; |
| 262 | 281 |
| 282 // Remove our help / halo menu if the mouse cursor is not still over it. | |
|
sky
2012/08/02 18:30:30
help/halo -> bubble
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 283 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); | |
|
sky
2012/08/02 18:30:30
event has a location, use it.
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
As stated in the comment: an event comes to an end
| |
| 284 if (!GetBoundsInScreen().Contains(screen_location)) | |
| 285 maximizer_.reset(); | |
|
sky
2012/08/02 18:30:30
You sure we don't want to reset always? In particu
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
See comment above.
| |
| 286 | |
| 263 if (!should_snap || snap_type_ == SNAP_NONE) | 287 if (!should_snap || snap_type_ == SNAP_NONE) |
| 264 return false; | 288 return false; |
| 265 | 289 |
| 266 SetState(BS_NORMAL); | 290 SetState(BS_NORMAL); |
| 267 // SetState will not call SchedulePaint() if state was already set to | 291 // SetState will not call SchedulePaint() if state was already set to |
| 268 // BS_NORMAL during a drag. | 292 // BS_NORMAL during a drag. |
| 269 SchedulePaint(); | 293 SchedulePaint(); |
| 270 phantom_window_.reset(); | 294 phantom_window_.reset(); |
| 271 Snap(); | 295 Snap(); |
| 272 return true; | 296 return true; |
| 273 } | 297 } |
| 274 | 298 |
| 275 void FrameMaximizeButton::Cancel() { | 299 void FrameMaximizeButton::Cancel() { |
| 300 maximizer_.reset(); | |
| 276 UninstallEventFilter(); | 301 UninstallEventFilter(); |
| 277 is_snap_enabled_ = false; | 302 is_snap_enabled_ = false; |
| 278 phantom_window_.reset(); | 303 phantom_window_.reset(); |
| 279 snap_sizer_.reset(); | 304 snap_sizer_.reset(); |
| 305 snap_type_ = SNAP_NONE; | |
| 280 update_timer_.Stop(); | 306 update_timer_.Stop(); |
| 281 SchedulePaint(); | 307 SchedulePaint(); |
| 282 } | 308 } |
| 283 | 309 |
| 284 void FrameMaximizeButton::InstallEventFilter() { | 310 void FrameMaximizeButton::InstallEventFilter() { |
| 285 if (escape_event_filter_.get()) | 311 if (escape_event_filter_.get()) |
| 286 return; | 312 return; |
| 287 | 313 |
| 288 escape_event_filter_.reset(new EscapeEventFilter(this)); | 314 escape_event_filter_.reset(new EscapeEventFilter(this)); |
| 289 } | 315 } |
| 290 | 316 |
| 291 void FrameMaximizeButton::UninstallEventFilter() { | 317 void FrameMaximizeButton::UninstallEventFilter() { |
| 292 escape_event_filter_.reset(NULL); | 318 escape_event_filter_.reset(NULL); |
| 293 } | 319 } |
| 294 | 320 |
| 295 void FrameMaximizeButton::UpdateSnapFromEventLocation() { | 321 void FrameMaximizeButton::UpdateSnapFromEventLocation() { |
| 296 // If the drag threshold has been exceeded the snap location is up to date. | 322 // If the drag threshold has been exceeded the snap location is up to date. |
| 297 if (exceeded_drag_threshold_) | 323 if (exceeded_drag_threshold_) |
| 298 return; | 324 return; |
| 299 exceeded_drag_threshold_ = true; | 325 exceeded_drag_threshold_ = true; |
| 300 UpdateSnap(press_location_); | 326 UpdateSnap(press_location_); |
| 301 } | 327 } |
| 302 | 328 |
| 329 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { | |
| 330 // Make sure to only show hover operations when no button is pressed and | |
| 331 // a similar snap operation in progress does not get re-applied. | |
| 332 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_.get())) | |
| 333 return; | |
| 334 // Prime the mouse location with the center of the (local) button. | |
| 335 press_location_ = gfx::Point(width() / 2, height() / 2); | |
| 336 // Then get an adjusted mouse position to initiate the effect. | |
| 337 gfx::Point location = press_location_; | |
| 338 switch (type) { | |
| 339 case SNAP_LEFT: | |
| 340 location.set_x(location.x() - width()); | |
| 341 break; | |
| 342 case SNAP_RIGHT: | |
| 343 location.set_x(location.x() + width()); | |
| 344 break; | |
| 345 case SNAP_MINIMIZE: | |
| 346 location.set_y(location.y() + height()); | |
| 347 break; | |
| 348 case SNAP_MAXIMIZE: | |
| 349 case SNAP_RESTORE: | |
| 350 break; | |
| 351 case SNAP_NONE: | |
| 352 snap_type_ = type; | |
|
sky
2012/08/02 18:30:30
Cancel()? Maybe you can't because you don't want t
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
There are two distinct operations: Button hover an
| |
| 353 snap_sizer_.reset(); | |
| 354 SchedulePaint(); | |
| 355 phantom_window_.reset(); | |
| 356 return; | |
| 357 default: | |
| 358 // We should not come here. | |
| 359 DCHECK(false); | |
|
sky
2012/08/02 18:30:30
NOTREACHED
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 360 return; | |
| 361 } | |
| 362 UpdateSnap(location); | |
| 363 } | |
| 364 | |
| 303 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { | 365 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { |
| 304 SnapType type = SnapTypeForLocation(location); | 366 SnapType type = SnapTypeForLocation(location); |
| 305 if (type == snap_type_) { | 367 if (type == snap_type_) { |
| 306 if (snap_sizer_.get()) { | 368 if (snap_sizer_.get()) { |
| 307 snap_sizer_->Update(LocationForSnapSizer(location)); | 369 snap_sizer_->Update(LocationForSnapSizer(location)); |
| 308 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( | 370 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( |
| 309 frame_->GetWidget()->GetNativeView()->parent(), | 371 frame_->GetWidget()->GetNativeView()->parent(), |
| 310 snap_sizer_->target_bounds())); | 372 snap_sizer_->target_bounds())); |
| 311 } | 373 } |
| 312 return; | 374 return; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 326 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; | 388 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; |
| 327 int grid_size = Shell::GetInstance()->GetGridSize(); | 389 int grid_size = Shell::GetInstance()->GetGridSize(); |
| 328 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), | 390 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), |
| 329 LocationForSnapSizer(location), | 391 LocationForSnapSizer(location), |
| 330 snap_edge, grid_size)); | 392 snap_edge, grid_size)); |
| 331 } | 393 } |
| 332 if (!phantom_window_.get()) { | 394 if (!phantom_window_.get()) { |
| 333 phantom_window_.reset(new internal::PhantomWindowController( | 395 phantom_window_.reset(new internal::PhantomWindowController( |
| 334 frame_->GetWidget()->GetNativeWindow())); | 396 frame_->GetWidget()->GetNativeWindow())); |
| 335 } | 397 } |
| 398 if (maximizer_.get()) | |
| 399 phantom_window_->set_phantom_below_window(maximizer_->GetMenuWindow()); | |
| 400 | |
| 336 phantom_window_->Show(ScreenBoundsForType(snap_type_)); | 401 phantom_window_->Show(ScreenBoundsForType(snap_type_)); |
| 402 | |
| 403 if (maximizer_.get()) | |
|
msw
2012/08/02 18:56:59
nit: if the order here isn't critical, combine thi
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Not for this menu - but for the other one. Okay -
| |
| 404 maximizer_->SetMenuState(snap_type_); | |
| 337 } | 405 } |
| 338 | 406 |
| 339 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( | 407 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( |
| 340 const gfx::Point& location) const { | 408 const gfx::Point& location) const { |
| 341 int delta_x = location.x() - press_location_.x(); | 409 int delta_x = location.x() - press_location_.x(); |
| 342 int delta_y = location.y() - press_location_.y(); | 410 int delta_y = location.y() - press_location_.y(); |
| 343 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) | 411 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) |
| 344 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | 412 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; |
| 345 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) | 413 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) |
| 346 return SNAP_LEFT; | 414 return SNAP_LEFT; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 return gfx::Rect(); | 453 return gfx::Rect(); |
| 386 } | 454 } |
| 387 | 455 |
| 388 gfx::Point FrameMaximizeButton::LocationForSnapSizer( | 456 gfx::Point FrameMaximizeButton::LocationForSnapSizer( |
| 389 const gfx::Point& location) const { | 457 const gfx::Point& location) const { |
| 390 gfx::Point result(location); | 458 gfx::Point result(location); |
| 391 views::View::ConvertPointToScreen(this, &result); | 459 views::View::ConvertPointToScreen(this, &result); |
| 392 return result; | 460 return result; |
| 393 } | 461 } |
| 394 | 462 |
| 463 void FrameMaximizeButton::ExecuteSnapAndCloseMenu(SnapType snap_type) { | |
|
sky
2012/08/02 18:30:30
Make sure order matches header.
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 464 snap_type_ = snap_type; | |
| 465 Snap(); | |
|
sky
2012/08/02 18:30:30
DCHECK_NE(snap_type_, SNAP_NONE).
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
I have to admit that I won't see any harm done if
| |
| 466 // Remove any pending snap previews. | |
| 467 SnapButtonHovered(SNAP_NONE); | |
| 468 // At this point the operation has been performed and the menu should be | |
| 469 // closed (due to the resize operation). If not, it'll get now closed. | |
| 470 if (maximizer_.get()) | |
|
sky
2012/08/02 18:30:30
no if. and comment is misleading since a minimize
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 471 maximizer_.reset(); | |
| 472 } | |
| 473 | |
| 395 void FrameMaximizeButton::Snap() { | 474 void FrameMaximizeButton::Snap() { |
| 396 switch (snap_type_) { | 475 switch (snap_type_) { |
| 397 case SNAP_LEFT: | 476 case SNAP_LEFT: |
| 398 case SNAP_RIGHT: | 477 case SNAP_RIGHT: |
| 399 if (frame_->GetWidget()->IsMaximized()) { | 478 if (frame_->GetWidget()->IsMaximized()) { |
| 400 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), | 479 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), |
| 401 ScreenBoundsForType(snap_type_)); | 480 ScreenBoundsForType(snap_type_)); |
| 402 frame_->GetWidget()->Restore(); | 481 frame_->GetWidget()->Restore(); |
| 403 } else { | 482 } else { |
| 404 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); | 483 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); |
| 405 } | 484 } |
| 406 break; | 485 break; |
| 407 case SNAP_MAXIMIZE: | 486 case SNAP_MAXIMIZE: |
| 408 frame_->GetWidget()->Maximize(); | 487 frame_->GetWidget()->Maximize(); |
| 409 break; | 488 break; |
| 410 case SNAP_MINIMIZE: | 489 case SNAP_MINIMIZE: |
| 411 frame_->GetWidget()->Minimize(); | 490 frame_->GetWidget()->Minimize(); |
| 412 break; | 491 break; |
| 413 case SNAP_RESTORE: | 492 case SNAP_RESTORE: |
| 414 frame_->GetWidget()->Restore(); | 493 frame_->GetWidget()->Restore(); |
| 415 break; | 494 break; |
| 416 case SNAP_NONE: | 495 case SNAP_NONE: |
| 417 NOTREACHED(); | 496 NOTREACHED(); |
| 418 } | 497 } |
| 419 } | 498 } |
| 420 | 499 |
| 500 void FrameMaximizeButton::DestroyMaximizeMenu() { | |
|
sky
2012/08/02 18:30:30
Make order match header.
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 501 if (maximizer_.get()) | |
| 502 maximizer_.reset(); | |
|
sky
2012/08/02 18:30:30
No need for the if. maximizer_.reset() does the ri
Mr4D (OOO till 08-26)
2012/08/02 23:10:38
Done.
| |
| 503 } | |
| 504 | |
| 421 } // namespace ash | 505 } // namespace ash |
| OLD | NEW |