| 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/maximize_bubble_controller.h" | 5 #include "ash/wm/maximize_bubble_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/wm/window_animations.h" | 9 #include "ash/wm/window_animations.h" |
| 10 #include "ash/wm/workspace/frame_maximize_button.h" | 10 #include "ash/wm/workspace/frame_maximize_button.h" |
| 11 #include "base/timer.h" | 11 #include "base/timer.h" |
| 12 #include "grit/ash_strings.h" | 12 #include "grit/ash_strings.h" |
| 13 #include "grit/ui_resources.h" | 13 #include "grit/ui_resources.h" |
| 14 #include "third_party/skia/include/core/SkPath.h" |
| 14 #include "ui/aura/focus_manager.h" | 15 #include "ui/aura/focus_manager.h" |
| 15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/base/animation/animation.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/path.h" |
| 19 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 20 #include "ui/views/bubble/bubble_delegate.h" | 23 #include "ui/views/bubble/bubble_delegate.h" |
| 21 #include "ui/views/bubble/bubble_frame_view.h" | 24 #include "ui/views/bubble/bubble_frame_view.h" |
| 22 #include "ui/views/controls/button/button.h" | 25 #include "ui/views/controls/button/button.h" |
| 23 #include "ui/views/controls/button/image_button.h" | 26 #include "ui/views/controls/button/image_button.h" |
| 24 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
| 25 #include "ui/views/events/event.h" | 28 #include "ui/views/events/event.h" |
| 26 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
| 27 #include "ui/views/mouse_watcher.h" | 30 #include "ui/views/mouse_watcher.h" |
| 28 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 // The spacing between two buttons. | 35 // The spacing between two buttons. |
| 33 const int kLayoutSpacing = -1; | 36 const int kLayoutSpacing = -1; |
| 34 | 37 |
| 35 // The background color. | 38 // The background color. |
| 36 const SkColor kBubbleBackgroundColor = 0xc8141414; | 39 const SkColor kBubbleBackgroundColor = 0xc8141414; |
| 37 | 40 |
| 38 // The text color within the bubble. | 41 // The text color within the bubble. |
| 39 const SkColor kBubbleTextColor = SK_ColorWHITE; | 42 const SkColor kBubbleTextColor = SK_ColorWHITE; |
| 40 | 43 |
| 41 // The line width of the bubble. | 44 // The line width of the bubble. |
| 42 const int kLineWidth = 1; | 45 const int kLineWidth = 1; |
| 43 | 46 |
| 47 // The spacing for the top and bottom of the info label. |
| 48 const int kLabelSpacing = 4; |
| 49 |
| 44 // The pixel dimensions of the arrow. | 50 // The pixel dimensions of the arrow. |
| 45 const int kArrowHeight = 10; | 51 const int kArrowHeight = 10; |
| 46 const int kArrowWidth = 20; | 52 const int kArrowWidth = 20; |
| 47 | 53 |
| 48 // The delay of the bubble appearance. | 54 // The delay of the bubble appearance. |
| 49 const int kBubbleAppearanceDelayMS = 200; | 55 const int kBubbleAppearanceDelayMS = 200; |
| 50 const int kAnimationDurationForPopupMS = 200; | 56 |
| 57 // The animation offset in y for the bubble when appearing. |
| 58 const int kBubbleAnimationOffsetY = 5; |
| 51 | 59 |
| 52 class MaximizeBubbleBorder : public views::BubbleBorder { | 60 class MaximizeBubbleBorder : public views::BubbleBorder { |
| 53 public: | 61 public: |
| 54 MaximizeBubbleBorder(views::View* content_view, views::View* anchor); | 62 MaximizeBubbleBorder(views::View* content_view, views::View* anchor); |
| 55 | 63 |
| 56 virtual ~MaximizeBubbleBorder() {} | 64 virtual ~MaximizeBubbleBorder() {} |
| 57 | 65 |
| 66 // Get the mouse active area of the window. |
| 67 void GetMask(gfx::Path* mask); |
| 68 |
| 58 // Overridden from views::BubbleBorder to match the design specs. | 69 // Overridden from views::BubbleBorder to match the design specs. |
| 59 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, | 70 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
| 60 const gfx::Size& contents_size) const OVERRIDE; | 71 const gfx::Size& contents_size) const OVERRIDE; |
| 61 | 72 |
| 62 // Overridden from views::Border. | 73 // Overridden from views::Border. |
| 63 virtual void Paint(const views::View& view, | 74 virtual void Paint(const views::View& view, |
| 64 gfx::Canvas* canvas) const OVERRIDE; | 75 gfx::Canvas* canvas) const OVERRIDE; |
| 76 |
| 65 private: | 77 private: |
| 66 views::View* anchor_; | 78 // Note: Animations can continue after then main window frame was destroyed. |
| 79 // To avoid this problem, the owning screen metrics get extracted upon |
| 80 // creation. |
| 81 gfx::Size anchor_size_; |
| 82 gfx::Point anchor_screen_origin_; |
| 67 views::View* content_view_; | 83 views::View* content_view_; |
| 68 | 84 |
| 69 DISALLOW_COPY_AND_ASSIGN(MaximizeBubbleBorder); | 85 DISALLOW_COPY_AND_ASSIGN(MaximizeBubbleBorder); |
| 70 }; | 86 }; |
| 71 | 87 |
| 72 MaximizeBubbleBorder::MaximizeBubbleBorder(views::View* content_view, | 88 MaximizeBubbleBorder::MaximizeBubbleBorder(views::View* content_view, |
| 73 views::View* anchor) | 89 views::View* anchor) |
| 74 : views::BubbleBorder(views::BubbleBorder::TOP_RIGHT, | 90 : views::BubbleBorder(views::BubbleBorder::TOP_RIGHT, |
| 75 views::BubbleBorder::NO_SHADOW), | 91 views::BubbleBorder::NO_SHADOW), |
| 76 anchor_(anchor), | 92 anchor_size_(anchor->size()), |
| 93 anchor_screen_origin_(0,0), |
| 77 content_view_(content_view) { | 94 content_view_(content_view) { |
| 95 views::View::ConvertPointToScreen(anchor, &anchor_screen_origin_); |
| 78 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 96 set_alignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 79 } | 97 } |
| 80 | 98 |
| 99 void MaximizeBubbleBorder::GetMask(gfx::Path* mask) { |
| 100 gfx::Insets inset; |
| 101 GetInsets(&inset); |
| 102 // Note: Even though the tip could be added as activatable, it is left out |
| 103 // since it would not change the action behavior in any way plus it makes |
| 104 // more sense to keep the focus on the underlying button for clicks. |
| 105 int left = inset.left() - kLineWidth; |
| 106 int right = inset.left() + content_view_->width() + kLineWidth; |
| 107 int top = inset.top() - kLineWidth; |
| 108 int bottom = inset.top() + content_view_->height() + kLineWidth; |
| 109 mask->moveTo(left, top); |
| 110 mask->lineTo(right, top); |
| 111 mask->lineTo(right, bottom); |
| 112 mask->lineTo(left, bottom); |
| 113 mask->lineTo(left, top); |
| 114 mask->close(); |
| 115 } |
| 116 |
| 81 gfx::Rect MaximizeBubbleBorder::GetBounds( | 117 gfx::Rect MaximizeBubbleBorder::GetBounds( |
| 82 const gfx::Rect& position_relative_to, | 118 const gfx::Rect& position_relative_to, |
| 83 const gfx::Size& contents_size) const { | 119 const gfx::Size& contents_size) const { |
| 84 gfx::Size border_size(contents_size); | 120 gfx::Size border_size(contents_size); |
| 85 gfx::Insets insets; | 121 gfx::Insets insets; |
| 86 GetInsets(&insets); | 122 GetInsets(&insets); |
| 87 border_size.Enlarge(insets.width(), insets.height()); | 123 border_size.Enlarge(insets.width(), insets.height()); |
| 88 | 124 |
| 89 // Position the bubble to center the box on the anchor. | 125 // Position the bubble to center the box on the anchor. |
| 90 int x = (-border_size.width() + anchor_->width()) / 2; | 126 int x = (-border_size.width() + anchor_size_.width()) / 2; |
| 91 // Position the bubble under the anchor, overlapping the arrow with it. | 127 // Position the bubble under the anchor, overlapping the arrow with it. |
| 92 int y = anchor_->height() - insets.top(); | 128 int y = anchor_size_.height() - insets.top(); |
| 93 | 129 |
| 94 gfx::Point view_origin(x, y); | 130 gfx::Point view_origin(x + anchor_screen_origin_.x(), |
| 95 views::View::ConvertPointToScreen(anchor_, &view_origin); | 131 y + anchor_screen_origin_.y()); |
| 96 | 132 |
| 97 return gfx::Rect(view_origin, border_size); | 133 return gfx::Rect(view_origin, border_size); |
| 98 } | 134 } |
| 99 | 135 |
| 100 void MaximizeBubbleBorder::Paint(const views::View& view, | 136 void MaximizeBubbleBorder::Paint(const views::View& view, |
| 101 gfx::Canvas* canvas) const { | 137 gfx::Canvas* canvas) const { |
| 102 gfx::Insets inset; | 138 gfx::Insets inset; |
| 103 GetInsets(&inset); | 139 GetInsets(&inset); |
| 104 | 140 |
| 105 // Draw the border line around everything. | 141 // Draw the border line around everything. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 public views::MouseWatcherListener { | 219 public views::MouseWatcherListener { |
| 184 public: | 220 public: |
| 185 explicit Bubble(MaximizeBubbleController* owner); | 221 explicit Bubble(MaximizeBubbleController* owner); |
| 186 virtual ~Bubble() {} | 222 virtual ~Bubble() {} |
| 187 | 223 |
| 188 // The window of the menu under which the SnapSizer will get created. | 224 // The window of the menu under which the SnapSizer will get created. |
| 189 aura::Window* GetBubbleWindow(); | 225 aura::Window* GetBubbleWindow(); |
| 190 | 226 |
| 191 // Overridden from views::BubbleDelegateView. | 227 // Overridden from views::BubbleDelegateView. |
| 192 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 228 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
| 229 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 230 |
| 231 // Overridden from views::WidgetDelegateView. |
| 232 virtual bool HasHitTestMask() const OVERRIDE; |
| 233 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE; |
| 193 | 234 |
| 194 // Implementation of MouseWatcherListener. | 235 // Implementation of MouseWatcherListener. |
| 195 virtual void MouseMovedOutOfHost(); | 236 virtual void MouseMovedOutOfHost(); |
| 196 | 237 |
| 197 // Implementation of MouseWatcherHost. | 238 // Implementation of MouseWatcherHost. |
| 198 virtual bool Contains(const gfx::Point& screen_point, | 239 virtual bool Contains(const gfx::Point& screen_point, |
| 199 views::MouseWatcherHost::MouseEventType type); | 240 views::MouseWatcherHost::MouseEventType type); |
| 200 | 241 |
| 201 // Overridden from views::View. | 242 // Overridden from views::View. |
| 202 virtual gfx::Size GetPreferredSize() OVERRIDE; | 243 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 222 | 263 |
| 223 // Our owning class. | 264 // Our owning class. |
| 224 MaximizeBubbleController* owner_; | 265 MaximizeBubbleController* owner_; |
| 225 | 266 |
| 226 // The widget which contains our menu and the bubble border. | 267 // The widget which contains our menu and the bubble border. |
| 227 views::Widget* bubble_widget_; | 268 views::Widget* bubble_widget_; |
| 228 | 269 |
| 229 // The content accessor of the menu. | 270 // The content accessor of the menu. |
| 230 BubbleContentsView* contents_view_; | 271 BubbleContentsView* contents_view_; |
| 231 | 272 |
| 273 // The bubble border. |
| 274 MaximizeBubbleBorder* bubble_border_; |
| 275 |
| 276 // The rectangle before the animation starts. |
| 277 gfx::Rect initial_position_; |
| 278 |
| 232 // The mouse watcher which takes care of out of window hover events. | 279 // The mouse watcher which takes care of out of window hover events. |
| 233 scoped_ptr<views::MouseWatcher> mouse_watcher_; | 280 scoped_ptr<views::MouseWatcher> mouse_watcher_; |
| 234 | 281 |
| 235 DISALLOW_COPY_AND_ASSIGN(Bubble); | 282 DISALLOW_COPY_AND_ASSIGN(Bubble); |
| 236 }; | 283 }; |
| 237 | 284 |
| 238 // A class that creates all buttons and put them into a view. | 285 // A class that creates all buttons and put them into a view. |
| 239 class BubbleContentsButtonRow : public views::View, | 286 class BubbleContentsButtonRow : public views::View, |
| 240 public views::ButtonListener { | 287 public views::ButtonListener { |
| 241 public: | 288 public: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 355 |
| 309 DISALLOW_COPY_AND_ASSIGN(BubbleDialogButton); | 356 DISALLOW_COPY_AND_ASSIGN(BubbleDialogButton); |
| 310 }; | 357 }; |
| 311 | 358 |
| 312 MaximizeBubbleController::Bubble::Bubble(MaximizeBubbleController* owner) | 359 MaximizeBubbleController::Bubble::Bubble(MaximizeBubbleController* owner) |
| 313 : views::BubbleDelegateView(owner->frame_maximize_button(), | 360 : views::BubbleDelegateView(owner->frame_maximize_button(), |
| 314 views::BubbleBorder::TOP_RIGHT), | 361 views::BubbleBorder::TOP_RIGHT), |
| 315 shutting_down_(false), | 362 shutting_down_(false), |
| 316 owner_(owner), | 363 owner_(owner), |
| 317 bubble_widget_(NULL), | 364 bubble_widget_(NULL), |
| 318 contents_view_(NULL) { | 365 contents_view_(NULL), |
| 366 bubble_border_(NULL) { |
| 319 set_margins(gfx::Insets()); | 367 set_margins(gfx::Insets()); |
| 320 | 368 |
| 321 // The window needs to be owned by the root so that the SnapSizer does not | 369 // The window needs to be owned by the root so that the SnapSizer does not |
| 322 // cover it upon animation. | 370 // cover it upon animation. |
| 323 aura::Window* parent = Shell::GetContainer( | 371 aura::Window* parent = Shell::GetContainer( |
| 324 Shell::GetActiveRootWindow(), | 372 Shell::GetActiveRootWindow(), |
| 325 internal::kShellWindowId_LauncherContainer); | 373 internal::kShellWindowId_LauncherContainer); |
| 326 set_parent_window(parent); | 374 set_parent_window(parent); |
| 327 | 375 |
| 328 set_notify_enter_exit_on_child(true); | 376 set_notify_enter_exit_on_child(true); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 340 contents_view_ = new BubbleContentsView(this); | 388 contents_view_ = new BubbleContentsView(this); |
| 341 AddChildView(contents_view_); | 389 AddChildView(contents_view_); |
| 342 | 390 |
| 343 // Note that the returned widget has an observer which points to our | 391 // Note that the returned widget has an observer which points to our |
| 344 // functions. | 392 // functions. |
| 345 bubble_widget_ = views::BubbleDelegateView::CreateBubble(this); | 393 bubble_widget_ = views::BubbleDelegateView::CreateBubble(this); |
| 346 | 394 |
| 347 SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 395 SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 348 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); | 396 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); |
| 349 | 397 |
| 350 MaximizeBubbleBorder* bubble_border = new MaximizeBubbleBorder( | 398 bubble_border_ = new MaximizeBubbleBorder(this, anchor_view()); |
| 351 this, | 399 GetBubbleFrameView()->SetBubbleBorder(bubble_border_); |
| 352 anchor_view()); | |
| 353 GetBubbleFrameView()->SetBubbleBorder(bubble_border); | |
| 354 GetBubbleFrameView()->set_background(NULL); | 400 GetBubbleFrameView()->set_background(NULL); |
| 355 | 401 |
| 356 // Recalculate size with new border. | 402 // Recalculate size with new border. |
| 357 SizeToContents(); | 403 SizeToContents(); |
| 358 | 404 |
| 359 // Setup animation. | 405 StartFade(true); |
| 360 ash::SetWindowVisibilityAnimationType( | |
| 361 bubble_widget_->GetNativeWindow(), | |
| 362 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
| 363 ash::SetWindowVisibilityAnimationTransition( | |
| 364 bubble_widget_->GetNativeWindow(), | |
| 365 ash::ANIMATE_BOTH); | |
| 366 ash::SetWindowVisibilityAnimationDuration( | |
| 367 bubble_widget_->GetNativeWindow(), | |
| 368 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); | |
| 369 | 406 |
| 370 Show(); | |
| 371 // We don't want to lose the focus on our parent window because the button | |
| 372 // would otherwise lose the highlight when the "helper bubble" is shown. | |
| 373 views::Widget* widget = | |
| 374 owner_->frame_maximize_button()->parent()->GetWidget(); | |
| 375 if (widget) { | |
| 376 aura::Window* parent_window = widget->GetNativeWindow(); | |
| 377 parent_window->GetFocusManager()->SetFocusedWindow(parent_window, NULL); | |
| 378 } | |
| 379 mouse_watcher_.reset(new views::MouseWatcher( | 407 mouse_watcher_.reset(new views::MouseWatcher( |
| 380 new BubbleMouseWatcherHost(this), | 408 new BubbleMouseWatcherHost(this), |
| 381 this)); | 409 this)); |
| 382 mouse_watcher_->Start(); | 410 mouse_watcher_->Start(); |
| 383 } | 411 } |
| 384 | 412 |
| 385 bool BubbleMouseWatcherHost::Contains( | 413 bool BubbleMouseWatcherHost::Contains( |
| 386 const gfx::Point& screen_point, | 414 const gfx::Point& screen_point, |
| 387 views::MouseWatcherHost::MouseEventType type) { | 415 views::MouseWatcherHost::MouseEventType type) { |
| 388 return bubble_->Contains(screen_point, type); | 416 return bubble_->Contains(screen_point, type); |
| 389 } | 417 } |
| 390 | 418 |
| 391 aura::Window* MaximizeBubbleController::Bubble::GetBubbleWindow() { | 419 aura::Window* MaximizeBubbleController::Bubble::GetBubbleWindow() { |
| 392 return bubble_widget_ ? bubble_widget_->GetNativeWindow() : NULL; | 420 return bubble_widget_ ? bubble_widget_->GetNativeWindow() : NULL; |
| 393 } | 421 } |
| 394 | 422 |
| 395 gfx::Rect MaximizeBubbleController::Bubble::GetAnchorRect() { | 423 gfx::Rect MaximizeBubbleController::Bubble::GetAnchorRect() { |
| 396 if (!owner_) | 424 if (!owner_) |
| 397 return gfx::Rect(); | 425 return gfx::Rect(); |
| 398 | 426 |
| 399 gfx::Rect anchor_rect = | 427 gfx::Rect anchor_rect = |
| 400 owner_->frame_maximize_button()->GetBoundsInScreen(); | 428 owner_->frame_maximize_button()->GetBoundsInScreen(); |
| 401 return anchor_rect; | 429 return anchor_rect; |
| 402 } | 430 } |
| 403 | 431 |
| 432 void MaximizeBubbleController::Bubble::AnimationProgressed( |
| 433 const ui::Animation* animation) { |
| 434 // First do everything needed for the fade by calling the base function. |
| 435 BubbleDelegateView::AnimationProgressed(animation); |
| 436 // When fading in we are done. |
| 437 if (!shutting_down_) |
| 438 return; |
| 439 // Upon fade out an additional shift is required. |
| 440 int shift = animation->CurrentValueBetween(kBubbleAnimationOffsetY, 0); |
| 441 gfx::Rect rect = initial_position_; |
| 442 |
| 443 rect.set_y(rect.y() + shift); |
| 444 bubble_widget_->GetNativeWindow()->SetBounds(rect); |
| 445 } |
| 446 |
| 447 bool MaximizeBubbleController::Bubble::HasHitTestMask() const { |
| 448 return bubble_border_ != NULL; |
| 449 } |
| 450 |
| 451 void MaximizeBubbleController::Bubble::GetHitTestMask(gfx::Path* mask) const { |
| 452 DCHECK(mask); |
| 453 DCHECK(bubble_border_); |
| 454 bubble_border_->GetMask(mask); |
| 455 } |
| 456 |
| 404 void MaximizeBubbleController::Bubble::MouseMovedOutOfHost() { | 457 void MaximizeBubbleController::Bubble::MouseMovedOutOfHost() { |
| 405 if (!owner_ || shutting_down_) | 458 if (!owner_ || shutting_down_) |
| 406 return; | 459 return; |
| 407 // When we leave the bubble, we might be still be in gesture mode or over | 460 // When we leave the bubble, we might be still be in gesture mode or over |
| 408 // the maximize button. So only close if none of the other cases apply. | 461 // the maximize button. So only close if none of the other cases apply. |
| 409 if (!owner_->frame_maximize_button()->is_snap_enabled()) { | 462 if (!owner_->frame_maximize_button()->is_snap_enabled()) { |
| 410 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); | 463 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); |
| 411 if (!owner_->frame_maximize_button()->GetBoundsInScreen().Contains( | 464 if (!owner_->frame_maximize_button()->GetBoundsInScreen().Contains( |
| 412 screen_location)) { | 465 screen_location)) { |
| 413 owner_->RequestDestructionThroughOwner(); | 466 owner_->RequestDestructionThroughOwner(); |
| 414 } | 467 } |
| 415 } | 468 } |
| 416 } | 469 } |
| 417 | 470 |
| 418 bool MaximizeBubbleController::Bubble::Contains( | 471 bool MaximizeBubbleController::Bubble::Contains( |
| 419 const gfx::Point& screen_point, | 472 const gfx::Point& screen_point, |
| 420 views::MouseWatcherHost::MouseEventType type) { | 473 views::MouseWatcherHost::MouseEventType type) { |
| 421 if (!owner_ || shutting_down_) | 474 if (!owner_ || shutting_down_) |
| 422 return false; | 475 return false; |
| 476 bool inside_button = |
| 477 owner_->frame_maximize_button()->GetBoundsInScreen().Contains( |
| 478 screen_point); |
| 479 if (!owner_->frame_maximize_button()->is_snap_enabled() && inside_button) { |
| 480 SetSnapType(controller()->is_maximized() ? SNAP_RESTORE : SNAP_MAXIMIZE); |
| 481 return true; |
| 482 } |
| 423 // Check if either a gesture is taking place (=> bubble stays no matter what | 483 // Check if either a gesture is taking place (=> bubble stays no matter what |
| 424 // the mouse does) or the mouse is over the maximize button or the bubble | 484 // the mouse does) or the mouse is over the maximize button or the bubble |
| 425 // content. | 485 // content. |
| 426 return (owner_->frame_maximize_button()->is_snap_enabled() || | 486 return (owner_->frame_maximize_button()->is_snap_enabled() || |
| 427 owner_->frame_maximize_button()->GetBoundsInScreen().Contains( | 487 inside_button || |
| 428 screen_point) || | |
| 429 contents_view_->GetBoundsInScreen().Contains(screen_point)); | 488 contents_view_->GetBoundsInScreen().Contains(screen_point)); |
| 430 } | 489 } |
| 431 | 490 |
| 432 gfx::Size MaximizeBubbleController::Bubble::GetPreferredSize() { | 491 gfx::Size MaximizeBubbleController::Bubble::GetPreferredSize() { |
| 433 return contents_view_->GetPreferredSize(); | 492 return contents_view_->GetPreferredSize(); |
| 434 } | 493 } |
| 435 | 494 |
| 436 void MaximizeBubbleController::Bubble::OnWidgetClosing(views::Widget* widget) { | 495 void MaximizeBubbleController::Bubble::OnWidgetClosing(views::Widget* widget) { |
| 437 if (bubble_widget_ != widget) | 496 if (bubble_widget_ != widget) |
| 438 return; | 497 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 451 anchor_widget()->RemoveObserver(this); | 510 anchor_widget()->RemoveObserver(this); |
| 452 } | 511 } |
| 453 | 512 |
| 454 void MaximizeBubbleController::Bubble::ControllerRequestsCloseAndDelete() { | 513 void MaximizeBubbleController::Bubble::ControllerRequestsCloseAndDelete() { |
| 455 // This only gets called from the owning base class once it is deleted. | 514 // This only gets called from the owning base class once it is deleted. |
| 456 if (shutting_down_) | 515 if (shutting_down_) |
| 457 return; | 516 return; |
| 458 shutting_down_ = true; | 517 shutting_down_ = true; |
| 459 owner_ = NULL; | 518 owner_ = NULL; |
| 460 | 519 |
| 461 // Close the widget asynchronously. | 520 // Close the widget asynchronously after the hide animation is finished. |
| 462 bubble_widget_->Close(); | 521 initial_position_ = bubble_widget_->GetNativeWindow()->bounds(); |
| 522 StartFade(false); |
| 463 } | 523 } |
| 464 | 524 |
| 465 void MaximizeBubbleController::Bubble::SetSnapType(SnapType snap_type) { | 525 void MaximizeBubbleController::Bubble::SetSnapType(SnapType snap_type) { |
| 466 if (contents_view_) | 526 if (contents_view_) |
| 467 contents_view_->SetSnapType(snap_type); | 527 contents_view_->SetSnapType(snap_type); |
| 468 } | 528 } |
| 469 | 529 |
| 470 BubbleContentsButtonRow::BubbleContentsButtonRow( | 530 BubbleContentsButtonRow::BubbleContentsButtonRow( |
| 471 MaximizeBubbleController::Bubble* bubble) | 531 MaximizeBubbleController::Bubble* bubble) |
| 472 : bubble_(bubble), | 532 : bubble_(bubble), |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 views::Background::CreateSolidBackground(kBubbleBackgroundColor)); | 597 views::Background::CreateSolidBackground(kBubbleBackgroundColor)); |
| 538 | 598 |
| 539 buttons_view_ = new BubbleContentsButtonRow(bubble); | 599 buttons_view_ = new BubbleContentsButtonRow(bubble); |
| 540 AddChildView(buttons_view_); | 600 AddChildView(buttons_view_); |
| 541 | 601 |
| 542 label_view_ = new views::Label(); | 602 label_view_ = new views::Label(); |
| 543 SetSnapType(SNAP_NONE); | 603 SetSnapType(SNAP_NONE); |
| 544 label_view_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); | 604 label_view_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); |
| 545 label_view_->SetBackgroundColor(kBubbleBackgroundColor); | 605 label_view_->SetBackgroundColor(kBubbleBackgroundColor); |
| 546 label_view_->SetEnabledColor(kBubbleTextColor); | 606 label_view_->SetEnabledColor(kBubbleTextColor); |
| 607 label_view_->set_border(views::Border::CreateEmptyBorder( |
| 608 kLabelSpacing, 0, kLabelSpacing, 0)); |
| 547 AddChildView(label_view_); | 609 AddChildView(label_view_); |
| 548 } | 610 } |
| 549 | 611 |
| 550 // Set the label content to reflect the currently selected |snap_type|. | 612 // Set the label content to reflect the currently selected |snap_type|. |
| 551 // This function can be executed through the frame maximize button as well as | 613 // This function can be executed through the frame maximize button as well as |
| 552 // through hover operations. | 614 // through hover operations. |
| 553 void BubbleContentsView::SetSnapType(SnapType snap_type) { | 615 void BubbleContentsView::SetSnapType(SnapType snap_type) { |
| 554 if (!bubble_->controller()) | 616 if (!bubble_->controller()) |
| 555 return; | 617 return; |
| 556 | 618 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 button_row_->ButtonHovered(this); | 734 button_row_->ButtonHovered(this); |
| 673 views::ImageButton::OnMouseEntered(event); | 735 views::ImageButton::OnMouseEntered(event); |
| 674 } | 736 } |
| 675 | 737 |
| 676 void BubbleDialogButton::OnMouseExited(const views::MouseEvent& event) { | 738 void BubbleDialogButton::OnMouseExited(const views::MouseEvent& event) { |
| 677 button_row_->ButtonHovered(NULL); | 739 button_row_->ButtonHovered(NULL); |
| 678 views::ImageButton::OnMouseExited(event); | 740 views::ImageButton::OnMouseExited(event); |
| 679 } | 741 } |
| 680 | 742 |
| 681 } // namespace ash | 743 } // namespace ash |
| OLD | NEW |