| 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 "ui/views/bubble/tray_bubble_view.h" | 5 #include "ui/views/bubble/tray_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 10 #include "third_party/skia/include/core/SkCanvas.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 AnchorAlignment anchor_alignment, | 274 AnchorAlignment anchor_alignment, |
| 275 int min_width, | 275 int min_width, |
| 276 int max_width) | 276 int max_width) |
| 277 : anchor_type(anchor_type), | 277 : anchor_type(anchor_type), |
| 278 anchor_alignment(anchor_alignment), | 278 anchor_alignment(anchor_alignment), |
| 279 min_width(min_width), | 279 min_width(min_width), |
| 280 max_width(max_width), | 280 max_width(max_width), |
| 281 max_height(0), | 281 max_height(0), |
| 282 can_activate(false), | 282 can_activate(false), |
| 283 close_on_deactivate(true), | 283 close_on_deactivate(true), |
| 284 close_via_capture(false), | |
| 285 arrow_color(SK_ColorBLACK), | 284 arrow_color(SK_ColorBLACK), |
| 286 first_item_has_no_margin(false), | 285 first_item_has_no_margin(false), |
| 287 arrow(BubbleBorder::NONE), | 286 arrow(BubbleBorder::NONE), |
| 288 arrow_offset(kArrowDefaultOffset), | 287 arrow_offset(kArrowDefaultOffset), |
| 289 arrow_paint_type(BubbleBorder::PAINT_NORMAL), | 288 arrow_paint_type(BubbleBorder::PAINT_NORMAL), |
| 290 shadow(BubbleBorder::BIG_SHADOW), | 289 shadow(BubbleBorder::BIG_SHADOW), |
| 291 arrow_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) {} | 290 arrow_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) { |
| 291 } |
| 292 | 292 |
| 293 TrayBubbleView::InitParams::InitParams(const InitParams& other) = default; | 293 TrayBubbleView::InitParams::InitParams(const InitParams& other) = default; |
| 294 | 294 |
| 295 // static | 295 // static |
| 296 TrayBubbleView* TrayBubbleView::Create(gfx::NativeView parent_window, | 296 TrayBubbleView* TrayBubbleView::Create(gfx::NativeView parent_window, |
| 297 View* anchor, | 297 View* anchor, |
| 298 Delegate* delegate, | 298 Delegate* delegate, |
| 299 InitParams* init_params) { | 299 InitParams* init_params) { |
| 300 // Set arrow here so that it can be passed to the BubbleView constructor. | 300 // Set arrow here so that it can be passed to the BubbleView constructor. |
| 301 if (init_params->anchor_type == ANCHOR_TYPE_TRAY) { | 301 if (init_params->anchor_type == ANCHOR_TYPE_TRAY) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // Must occur after call to BubbleDelegateView::CreateBubble(). | 349 // Must occur after call to BubbleDelegateView::CreateBubble(). |
| 350 SetAlignment(params_.arrow_alignment); | 350 SetAlignment(params_.arrow_alignment); |
| 351 bubble_border_->UpdateArrowOffset(); | 351 bubble_border_->UpdateArrowOffset(); |
| 352 | 352 |
| 353 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); | 353 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); |
| 354 | 354 |
| 355 GetWidget()->Show(); | 355 GetWidget()->Show(); |
| 356 GetWidget()->GetNativeWindow()->SetEventTargeter( | 356 GetWidget()->GetNativeWindow()->SetEventTargeter( |
| 357 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); | 357 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); |
| 358 UpdateBubble(); | 358 UpdateBubble(); |
| 359 | |
| 360 if (params_.close_via_capture) { | |
| 361 GetWidget()->set_auto_release_capture(false); | |
| 362 // Capture events to this view so it will be notified of capture loss. | |
| 363 GetWidget()->SetCapture(this); | |
| 364 } | |
| 365 } | 359 } |
| 366 | 360 |
| 367 void TrayBubbleView::UpdateBubble() { | 361 void TrayBubbleView::UpdateBubble() { |
| 368 if (GetWidget()) { | 362 if (GetWidget()) { |
| 369 SizeToContents(); | 363 SizeToContents(); |
| 370 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); | 364 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); |
| 371 GetWidget()->GetRootView()->SchedulePaint(); | 365 GetWidget()->GetRootView()->SchedulePaint(); |
| 372 } | 366 } |
| 373 } | 367 } |
| 374 | 368 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 for (int i = 0; i < child_count(); ++i) { | 441 for (int i = 0; i < child_count(); ++i) { |
| 448 const View* child = child_at(i); | 442 const View* child = child_at(i); |
| 449 if (child->visible()) | 443 if (child->visible()) |
| 450 height += child->GetHeightForWidth(width); | 444 height += child->GetHeightForWidth(width); |
| 451 } | 445 } |
| 452 | 446 |
| 453 return (params_.max_height != 0) ? | 447 return (params_.max_height != 0) ? |
| 454 std::min(height, params_.max_height) : height; | 448 std::min(height, params_.max_height) : height; |
| 455 } | 449 } |
| 456 | 450 |
| 457 void TrayBubbleView::OnMouseCaptureLost() { | |
| 458 if (params_.close_via_capture && delegate_) { | |
| 459 // Let the delegate destroy the bubble in case it needs to do cleanup. | |
| 460 delegate_->HideBubble(this); | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { | 451 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { |
| 465 mouse_watcher_.reset(); | 452 mouse_watcher_.reset(); |
| 466 if (delegate_ && !(event.flags() & ui::EF_IS_SYNTHESIZED)) { | 453 if (delegate_ && !(event.flags() & ui::EF_IS_SYNTHESIZED)) { |
| 467 // Coming here the user was actively moving the mouse over the bubble and | 454 // Coming here the user was actively moving the mouse over the bubble and |
| 468 // we inform the delegate that we entered. This will prevent the bubble | 455 // we inform the delegate that we entered. This will prevent the bubble |
| 469 // to auto close. | 456 // to auto close. |
| 470 delegate_->OnMouseEnteredView(); | 457 delegate_->OnMouseEnteredView(); |
| 471 mouse_actively_entered_ = true; | 458 mouse_actively_entered_ = true; |
| 472 } else { | 459 } else { |
| 473 // Coming here the bubble got shown and the mouse was 'accidentally' over it | 460 // Coming here the bubble got shown and the mouse was 'accidentally' over it |
| (...skipping 14 matching lines...) Expand all Loading... |
| 488 | 475 |
| 489 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { | 476 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { |
| 490 // If there was a mouse watcher waiting for mouse movements we disable it | 477 // If there was a mouse watcher waiting for mouse movements we disable it |
| 491 // immediately since we now leave the bubble. | 478 // immediately since we now leave the bubble. |
| 492 mouse_watcher_.reset(); | 479 mouse_watcher_.reset(); |
| 493 // Do not notify the delegate of an exit if we never told it that we entered. | 480 // Do not notify the delegate of an exit if we never told it that we entered. |
| 494 if (delegate_ && mouse_actively_entered_) | 481 if (delegate_ && mouse_actively_entered_) |
| 495 delegate_->OnMouseExitedView(); | 482 delegate_->OnMouseExitedView(); |
| 496 } | 483 } |
| 497 | 484 |
| 498 bool TrayBubbleView::OnMousePressed(const ui::MouseEvent& event) { | |
| 499 if (params_.close_via_capture && GetWidget()->HasCapture() && | |
| 500 !bounds().Contains(event.location())) { | |
| 501 // Explicitly releasing capture will close the bubble. | |
| 502 GetWidget()->ReleaseCapture(); | |
| 503 // Don't return that the event was handled because other views may want to | |
| 504 // handle it or the window server may want to repost it. | |
| 505 } | |
| 506 return views::BubbleDelegateView::OnMousePressed(event); | |
| 507 } | |
| 508 | |
| 509 void TrayBubbleView::GetAccessibleState(ui::AXViewState* state) { | 485 void TrayBubbleView::GetAccessibleState(ui::AXViewState* state) { |
| 510 if (delegate_ && params_.can_activate) { | 486 if (delegate_ && params_.can_activate) { |
| 511 state->role = ui::AX_ROLE_WINDOW; | 487 state->role = ui::AX_ROLE_WINDOW; |
| 512 state->name = delegate_->GetAccessibleNameForBubble(); | 488 state->name = delegate_->GetAccessibleNameForBubble(); |
| 513 } | 489 } |
| 514 } | 490 } |
| 515 | 491 |
| 516 void TrayBubbleView::MouseMovedOutOfHost() { | 492 void TrayBubbleView::MouseMovedOutOfHost() { |
| 517 // The mouse was accidentally over the bubble when it opened and the AutoClose | 493 // The mouse was accidentally over the bubble when it opened and the AutoClose |
| 518 // logic was not activated. Now that the user did move the mouse we tell the | 494 // logic was not activated. Now that the user did move the mouse we tell the |
| 519 // delegate to disable AutoClose. | 495 // delegate to disable AutoClose. |
| 520 delegate_->OnMouseEnteredView(); | 496 delegate_->OnMouseEnteredView(); |
| 521 mouse_actively_entered_ = true; | 497 mouse_actively_entered_ = true; |
| 522 mouse_watcher_->Stop(); | 498 mouse_watcher_->Stop(); |
| 523 } | 499 } |
| 524 | 500 |
| 525 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { | 501 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { |
| 526 SizeToContents(); | 502 SizeToContents(); |
| 527 } | 503 } |
| 528 | 504 |
| 529 void TrayBubbleView::ViewHierarchyChanged( | 505 void TrayBubbleView::ViewHierarchyChanged( |
| 530 const ViewHierarchyChangedDetails& details) { | 506 const ViewHierarchyChangedDetails& details) { |
| 531 if (details.is_add && details.child == this) { | 507 if (details.is_add && details.child == this) { |
| 532 details.parent->SetPaintToLayer(true); | 508 details.parent->SetPaintToLayer(true); |
| 533 details.parent->layer()->SetMasksToBounds(true); | 509 details.parent->layer()->SetMasksToBounds(true); |
| 534 } | 510 } |
| 535 } | 511 } |
| 536 | 512 |
| 537 } // namespace views | 513 } // namespace views |
| OLD | NEW |