| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/views/status_bubble_views.h" | 5 #include "chrome/browser/views/status_bubble_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
| 10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/animation.h" | 12 #include "app/animation.h" |
| 13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 14 #include "base/gfx/point.h" |
| 14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "chrome/browser/browser_theme_provider.h" | 17 #include "chrome/browser/browser_theme_provider.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 21 #include "third_party/skia/include/core/SkPaint.h" | 22 #include "third_party/skia/include/core/SkPaint.h" |
| 22 #include "third_party/skia/include/core/SkPath.h" | 23 #include "third_party/skia/include/core/SkPath.h" |
| 23 #include "third_party/skia/include/core/SkRect.h" | 24 #include "third_party/skia/include/core/SkRect.h" |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 view_->SetText(url_text_); | 566 view_->SetText(url_text_); |
| 566 } | 567 } |
| 567 | 568 |
| 568 void StatusBubbleViews::Hide() { | 569 void StatusBubbleViews::Hide() { |
| 569 status_text_ = std::wstring(); | 570 status_text_ = std::wstring(); |
| 570 url_text_ = std::wstring(); | 571 url_text_ = std::wstring(); |
| 571 if (view_) | 572 if (view_) |
| 572 view_->Hide(); | 573 view_->Hide(); |
| 573 } | 574 } |
| 574 | 575 |
| 575 void StatusBubbleViews::MouseMoved() { | 576 void StatusBubbleViews::MouseMoved(const gfx::Point& location, |
| 577 bool left_content) { |
| 578 if (left_content) |
| 579 return; |
| 580 |
| 576 if (view_) { | 581 if (view_) { |
| 577 view_->ResetTimer(); | 582 view_->ResetTimer(); |
| 578 | 583 |
| 579 if (view_->GetState() != StatusView::BUBBLE_HIDDEN && | 584 if (view_->GetState() != StatusView::BUBBLE_HIDDEN && |
| 580 view_->GetState() != StatusView::BUBBLE_HIDING_FADE && | 585 view_->GetState() != StatusView::BUBBLE_HIDING_FADE && |
| 581 view_->GetState() != StatusView::BUBBLE_HIDING_TIMER) { | 586 view_->GetState() != StatusView::BUBBLE_HIDING_TIMER) { |
| 582 AvoidMouse(); | 587 AvoidMouse(location); |
| 583 } | 588 } |
| 584 } | 589 } |
| 585 } | 590 } |
| 586 | 591 |
| 587 void StatusBubbleViews::UpdateDownloadShelfVisibility(bool visible) { | 592 void StatusBubbleViews::UpdateDownloadShelfVisibility(bool visible) { |
| 588 download_shelf_is_visible_ = visible; | 593 download_shelf_is_visible_ = visible; |
| 589 } | 594 } |
| 590 | 595 |
| 591 void StatusBubbleViews::AvoidMouse() { | 596 void StatusBubbleViews::AvoidMouse(const gfx::Point& location) { |
| 592 // Get the position of the frame. | 597 // Get the position of the frame. |
| 593 gfx::Point top_left; | 598 gfx::Point top_left; |
| 594 views::RootView* root = frame_->GetRootView(); | 599 views::RootView* root = frame_->GetRootView(); |
| 595 views::View::ConvertPointToScreen(root, &top_left); | 600 views::View::ConvertPointToScreen(root, &top_left); |
| 596 int window_width = root->GetLocalBounds(true).width(); // border included. | 601 int window_width = root->GetLocalBounds(true).width(); // border included. |
| 597 | 602 |
| 598 // Our status bubble is located in screen coordinates, so we should get | |
| 599 // those rather than attempting to reverse decode the web contents | |
| 600 // coordinates. | |
| 601 gfx::Point cursor_location = views::Screen::GetCursorScreenPoint(); | |
| 602 | |
| 603 // Get the cursor position relative to the popup. | 603 // Get the cursor position relative to the popup. |
| 604 gfx::Point relative_location = location; |
| 604 if (view_->UILayoutIsRightToLeft()) { | 605 if (view_->UILayoutIsRightToLeft()) { |
| 605 int top_right_x = top_left.x() + window_width; | 606 int top_right_x = top_left.x() + window_width; |
| 606 cursor_location.set_x(top_right_x - cursor_location.x()); | 607 relative_location.set_x(top_right_x - relative_location.x()); |
| 607 } else { | 608 } else { |
| 608 cursor_location.set_x(cursor_location.x() - (top_left.x() + position_.x())); | 609 relative_location.set_x( |
| 610 relative_location.x() - (top_left.x() + position_.x())); |
| 609 } | 611 } |
| 610 cursor_location.set_y(cursor_location.y() - (top_left.y() + position_.y())); | 612 relative_location.set_y( |
| 613 relative_location.y() - (top_left.y() + position_.y())); |
| 611 | 614 |
| 612 // If the mouse is in a position where we think it would move the | 615 // If the mouse is in a position where we think it would move the |
| 613 // status bubble, figure out where and how the bubble should be moved. | 616 // status bubble, figure out where and how the bubble should be moved. |
| 614 if (cursor_location.y() > -kMousePadding && | 617 if (relative_location.y() > -kMousePadding && |
| 615 cursor_location.x() < size_.width() + kMousePadding) { | 618 relative_location.x() < size_.width() + kMousePadding) { |
| 616 int offset = kMousePadding + cursor_location.y(); | 619 int offset = kMousePadding + relative_location.y(); |
| 617 | 620 |
| 618 // Make the movement non-linear. | 621 // Make the movement non-linear. |
| 619 offset = offset * offset / kMousePadding; | 622 offset = offset * offset / kMousePadding; |
| 620 | 623 |
| 621 // When the mouse is entering from the right, we want the offset to be | 624 // When the mouse is entering from the right, we want the offset to be |
| 622 // scaled by how horizontally far away the cursor is from the bubble. | 625 // scaled by how horizontally far away the cursor is from the bubble. |
| 623 if (cursor_location.x() > size_.width()) { | 626 if (relative_location.x() > size_.width()) { |
| 624 offset = static_cast<int>(static_cast<float>(offset) * ( | 627 offset = static_cast<int>(static_cast<float>(offset) * ( |
| 625 static_cast<float>(kMousePadding - | 628 static_cast<float>(kMousePadding - |
| 626 (cursor_location.x() - size_.width())) / | 629 (relative_location.x() - size_.width())) / |
| 627 static_cast<float>(kMousePadding))); | 630 static_cast<float>(kMousePadding))); |
| 628 } | 631 } |
| 629 | 632 |
| 630 // Cap the offset and change the visual presentation of the bubble | 633 // Cap the offset and change the visual presentation of the bubble |
| 631 // depending on where it ends up (so that rounded corners square off | 634 // depending on where it ends up (so that rounded corners square off |
| 632 // and mate to the edges of the tab content). | 635 // and mate to the edges of the tab content). |
| 633 if (offset >= size_.height() - kShadowThickness * 2) { | 636 if (offset >= size_.height() - kShadowThickness * 2) { |
| 634 offset = size_.height() - kShadowThickness * 2; | 637 offset = size_.height() - kShadowThickness * 2; |
| 635 view_->SetStyle(StatusView::STYLE_BOTTOM); | 638 view_->SetStyle(StatusView::STYLE_BOTTOM); |
| 636 } else if (offset > kBubbleCornerRadius / 2 - kShadowThickness) { | 639 } else if (offset > kBubbleCornerRadius / 2 - kShadowThickness) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 679 } |
| 677 } | 680 } |
| 678 | 681 |
| 679 bool StatusBubbleViews::IsFrameVisible() { | 682 bool StatusBubbleViews::IsFrameVisible() { |
| 680 if (!frame_->IsVisible()) | 683 if (!frame_->IsVisible()) |
| 681 return false; | 684 return false; |
| 682 | 685 |
| 683 views::Window* window = frame_->GetWindow(); | 686 views::Window* window = frame_->GetWindow(); |
| 684 return !window || !window->IsMinimized(); | 687 return !window || !window->IsMinimized(); |
| 685 } | 688 } |
| OLD | NEW |