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 "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), | |
| 284 arrow_color(SK_ColorBLACK), | 285 arrow_color(SK_ColorBLACK), |
| 285 first_item_has_no_margin(false), | 286 first_item_has_no_margin(false), |
| 286 arrow(BubbleBorder::NONE), | 287 arrow(BubbleBorder::NONE), |
| 287 arrow_offset(kArrowDefaultOffset), | 288 arrow_offset(kArrowDefaultOffset), |
| 288 arrow_paint_type(BubbleBorder::PAINT_NORMAL), | 289 arrow_paint_type(BubbleBorder::PAINT_NORMAL), |
| 289 shadow(BubbleBorder::BIG_SHADOW), | 290 shadow(BubbleBorder::BIG_SHADOW), |
| 290 arrow_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) { | 291 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 scoped_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); | 357 scoped_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); | |
|
sadrul
2016/04/14 20:08:35
This unfortunately breaks clicking in the tray-bub
James Cook
2016/04/14 23:05:12
Unfortunately setting the capture to a nullptr vie
| |
| 364 } | |
| 359 } | 365 } |
| 360 | 366 |
| 361 void TrayBubbleView::UpdateBubble() { | 367 void TrayBubbleView::UpdateBubble() { |
| 362 if (GetWidget()) { | 368 if (GetWidget()) { |
| 363 SizeToContents(); | 369 SizeToContents(); |
| 364 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); | 370 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); |
| 365 GetWidget()->GetRootView()->SchedulePaint(); | 371 GetWidget()->GetRootView()->SchedulePaint(); |
| 366 } | 372 } |
| 367 } | 373 } |
| 368 | 374 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 for (int i = 0; i < child_count(); ++i) { | 447 for (int i = 0; i < child_count(); ++i) { |
| 442 const View* child = child_at(i); | 448 const View* child = child_at(i); |
| 443 if (child->visible()) | 449 if (child->visible()) |
| 444 height += child->GetHeightForWidth(width); | 450 height += child->GetHeightForWidth(width); |
| 445 } | 451 } |
| 446 | 452 |
| 447 return (params_.max_height != 0) ? | 453 return (params_.max_height != 0) ? |
| 448 std::min(height, params_.max_height) : height; | 454 std::min(height, params_.max_height) : height; |
| 449 } | 455 } |
| 450 | 456 |
| 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 | |
| 451 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { | 464 void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { |
| 452 mouse_watcher_.reset(); | 465 mouse_watcher_.reset(); |
| 453 if (delegate_ && !(event.flags() & ui::EF_IS_SYNTHESIZED)) { | 466 if (delegate_ && !(event.flags() & ui::EF_IS_SYNTHESIZED)) { |
| 454 // Coming here the user was actively moving the mouse over the bubble and | 467 // Coming here the user was actively moving the mouse over the bubble and |
| 455 // we inform the delegate that we entered. This will prevent the bubble | 468 // we inform the delegate that we entered. This will prevent the bubble |
| 456 // to auto close. | 469 // to auto close. |
| 457 delegate_->OnMouseEnteredView(); | 470 delegate_->OnMouseEnteredView(); |
| 458 mouse_actively_entered_ = true; | 471 mouse_actively_entered_ = true; |
| 459 } else { | 472 } else { |
| 460 // Coming here the bubble got shown and the mouse was 'accidentally' over it | 473 // Coming here the bubble got shown and the mouse was 'accidentally' over it |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 475 | 488 |
| 476 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { | 489 void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { |
| 477 // If there was a mouse watcher waiting for mouse movements we disable it | 490 // If there was a mouse watcher waiting for mouse movements we disable it |
| 478 // immediately since we now leave the bubble. | 491 // immediately since we now leave the bubble. |
| 479 mouse_watcher_.reset(); | 492 mouse_watcher_.reset(); |
| 480 // Do not notify the delegate of an exit if we never told it that we entered. | 493 // Do not notify the delegate of an exit if we never told it that we entered. |
| 481 if (delegate_ && mouse_actively_entered_) | 494 if (delegate_ && mouse_actively_entered_) |
| 482 delegate_->OnMouseExitedView(); | 495 delegate_->OnMouseExitedView(); |
| 483 } | 496 } |
| 484 | 497 |
| 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 | |
| 485 void TrayBubbleView::GetAccessibleState(ui::AXViewState* state) { | 509 void TrayBubbleView::GetAccessibleState(ui::AXViewState* state) { |
| 486 if (delegate_ && params_.can_activate) { | 510 if (delegate_ && params_.can_activate) { |
| 487 state->role = ui::AX_ROLE_WINDOW; | 511 state->role = ui::AX_ROLE_WINDOW; |
| 488 state->name = delegate_->GetAccessibleNameForBubble(); | 512 state->name = delegate_->GetAccessibleNameForBubble(); |
| 489 } | 513 } |
| 490 } | 514 } |
| 491 | 515 |
| 492 void TrayBubbleView::MouseMovedOutOfHost() { | 516 void TrayBubbleView::MouseMovedOutOfHost() { |
| 493 // The mouse was accidentally over the bubble when it opened and the AutoClose | 517 // The mouse was accidentally over the bubble when it opened and the AutoClose |
| 494 // logic was not activated. Now that the user did move the mouse we tell the | 518 // logic was not activated. Now that the user did move the mouse we tell the |
| 495 // delegate to disable AutoClose. | 519 // delegate to disable AutoClose. |
| 496 delegate_->OnMouseEnteredView(); | 520 delegate_->OnMouseEnteredView(); |
| 497 mouse_actively_entered_ = true; | 521 mouse_actively_entered_ = true; |
| 498 mouse_watcher_->Stop(); | 522 mouse_watcher_->Stop(); |
| 499 } | 523 } |
| 500 | 524 |
| 501 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { | 525 void TrayBubbleView::ChildPreferredSizeChanged(View* child) { |
| 502 SizeToContents(); | 526 SizeToContents(); |
| 503 } | 527 } |
| 504 | 528 |
| 505 void TrayBubbleView::ViewHierarchyChanged( | 529 void TrayBubbleView::ViewHierarchyChanged( |
| 506 const ViewHierarchyChangedDetails& details) { | 530 const ViewHierarchyChangedDetails& details) { |
| 507 if (details.is_add && details.child == this) { | 531 if (details.is_add && details.child == this) { |
| 508 details.parent->SetPaintToLayer(true); | 532 details.parent->SetPaintToLayer(true); |
| 509 details.parent->layer()->SetMasksToBounds(true); | 533 details.parent->layer()->SetMasksToBounds(true); |
| 510 } | 534 } |
| 511 } | 535 } |
| 512 | 536 |
| 513 } // namespace views | 537 } // namespace views |
| OLD | NEW |