diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-16 20:10:55 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-16 20:10:55 +0000 |
commit | de54a5f6e53a3aa2cd218cb5f19aaf205af382d5 (patch) | |
tree | 7dd0e6e09da4c02417905b2ddbba7ee0b08bd67b | |
parent | 29fcba36dd2859ffdbfbbd714cb0427cebfcf332 (diff) | |
download | chromium_src-de54a5f6e53a3aa2cd218cb5f19aaf205af382d5.zip chromium_src-de54a5f6e53a3aa2cd218cb5f19aaf205af382d5.tar.gz chromium_src-de54a5f6e53a3aa2cd218cb5f19aaf205af382d5.tar.bz2 |
Commit for Yusuke. http://codereview.chromium.org/106005
Prevent the status bubble from getting pushed down below the screen.
BUG=4821
TEST=Open a page with a link in the bottom left corner, verify that the status bubble appears to the right. Verify that the status bubble appears in a normal position for all other links
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16240 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/status_bubble_views.cc | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc index 250614b..8a83fd9 100644 --- a/chrome/browser/views/status_bubble_views.cc +++ b/chrome/browser/views/status_bubble_views.cc @@ -101,7 +101,8 @@ class StatusBubbleViews::StatusView : public views::Label, typedef enum BubbleStyle { STYLE_BOTTOM, STYLE_FLOATING, - STYLE_STANDARD + STYLE_STANDARD, + STYLE_STANDARD_RIGHT }; // Set the bubble text to a certain value, hides the bubble if text is @@ -112,6 +113,8 @@ class StatusBubbleViews::StatusView : public views::Label, void SetStyle(BubbleStyle style); + BubbleStyle GetStyle() const { return style_; } + // Show the bubble instantly. void Show(); @@ -343,7 +346,9 @@ void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { rad[2] = 0; rad[3] = 0; } else { - if (UILayoutIsRightToLeft()) { + if (UILayoutIsRightToLeft() ^ (style_ == STYLE_STANDARD_RIGHT)) { + // The text is RtL or the bubble is on the right side (but not both). + // Top Left corner. rad[0] = SkIntToScalar(kBubbleCornerRadius); rad[1] = SkIntToScalar(kBubbleCornerRadius); @@ -364,7 +369,7 @@ void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { // Bottom edges - square these off if the bubble is in its standard position // (sticking upward). - if (style_ == STYLE_STANDARD) { + if (style_ == STYLE_STANDARD || style_ == STYLE_STANDARD_RIGHT) { // Bottom Right Corner. rad[4] = 0; rad[5] = 0; @@ -551,7 +556,8 @@ void StatusBubbleViews::AvoidMouse() { // Get the position of the frame. gfx::Point top_left; - views::View::ConvertPointToScreen(frame_->GetRootView(), &top_left); + views::RootView* root = frame_->GetRootView(); + views::View::ConvertPointToScreen(root, &top_left); // Get the cursor position relative to the popup. cursor_location.x -= (top_left.x() + position_.x); @@ -587,12 +593,36 @@ void StatusBubbleViews::AvoidMouse() { view_->SetStyle(StatusView::STYLE_STANDARD); } - offset_ = offset; - popup_->MoveWindow(top_left.x() + position_.x, - top_left.y() + position_.y + offset_, - size_.cx, - size_.cy); - } else if (offset_ != 0) { + // Check if the bubble sticks out from the monitor. + MONITORINFO monitor_info; + monitor_info.cbSize = sizeof(monitor_info); + GetMonitorInfo(MonitorFromWindow(frame_->GetNativeView(), + MONITOR_DEFAULTTONEAREST), &monitor_info); + gfx::Rect monitor_rect(monitor_info.rcWork); + const int bubble_bottom_y = top_left.y() + position_.y + size_.cy; + + if (bubble_bottom_y + offset > monitor_rect.height()) { + // The offset is still too large. Move the bubble to the right and reset + // Y offset_ to zero. + view_->SetStyle(StatusView::STYLE_STANDARD_RIGHT); + offset_ = 0; + + int root_width = root->GetLocalBounds(true).width(); // border included. + // Substract border width + bubble width. + int right_position_x = root_width - (position_.x + size_.cx); + popup_->MoveWindow(top_left.x() + right_position_x, + top_left.y() + position_.y, + size_.cx, + size_.cy); + } else { + offset_ = offset; + popup_->MoveWindow(top_left.x() + position_.x, + top_left.y() + position_.y + offset_, + size_.cx, + size_.cy); + } + } else if (offset_ != 0 || + view_->GetStyle() == StatusView::STYLE_STANDARD_RIGHT) { offset_ = 0; view_->SetStyle(StatusView::STYLE_STANDARD); popup_->MoveWindow(top_left.x() + position_.x, |