OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/status_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/status_bubble_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 SetStatusTextToURL(); | 90 SetStatusTextToURL(); |
91 } | 91 } |
92 | 92 |
93 void StatusBubbleGtk::SetStatusTextToURL() { | 93 void StatusBubbleGtk::SetStatusTextToURL() { |
94 GtkWidget* parent = gtk_widget_get_parent(container_.get()); | 94 GtkWidget* parent = gtk_widget_get_parent(container_.get()); |
95 | 95 |
96 // It appears that parent can be NULL (probably only during shutdown). | 96 // It appears that parent can be NULL (probably only during shutdown). |
97 if (!parent || !gtk_widget_get_realized(parent)) | 97 if (!parent || !gtk_widget_get_realized(parent)) |
98 return; | 98 return; |
99 | 99 |
100 int desired_width = parent->allocation.width; | 100 GtkAllocation allocation; |
| 101 gtk_widget_get_allocation(parent, &allocation); |
| 102 int desired_width = allocation.width; |
101 if (!expanded()) { | 103 if (!expanded()) { |
102 expand_timer_.Stop(); | 104 expand_timer_.Stop(); |
103 expand_timer_.Start(FROM_HERE, | 105 expand_timer_.Start(FROM_HERE, |
104 base::TimeDelta::FromMilliseconds(kExpandHoverDelay), | 106 base::TimeDelta::FromMilliseconds(kExpandHoverDelay), |
105 this, &StatusBubbleGtk::ExpandURL); | 107 this, &StatusBubbleGtk::ExpandURL); |
106 // When not expanded, we limit the size to one third the browser's | 108 // When not expanded, we limit the size to one third the browser's |
107 // width. | 109 // width. |
108 desired_width /= 3; | 110 desired_width /= 3; |
109 } | 111 } |
110 | 112 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } else { | 185 } else { |
184 GtkWidget* toplevel = gtk_widget_get_toplevel(container_.get()); | 186 GtkWidget* toplevel = gtk_widget_get_toplevel(container_.get()); |
185 if (!toplevel || !gtk_widget_get_realized(toplevel)) | 187 if (!toplevel || !gtk_widget_get_realized(toplevel)) |
186 return; | 188 return; |
187 | 189 |
188 bool ltr = !base::i18n::IsRTL(); | 190 bool ltr = !base::i18n::IsRTL(); |
189 | 191 |
190 GtkRequisition requisition; | 192 GtkRequisition requisition; |
191 gtk_widget_size_request(container_.get(), &requisition); | 193 gtk_widget_size_request(container_.get(), &requisition); |
192 | 194 |
| 195 GtkAllocation parent_allocation; |
| 196 gtk_widget_get_allocation(parent, &parent_allocation); |
| 197 |
193 // Get our base position (that is, not including the current offset) | 198 // Get our base position (that is, not including the current offset) |
194 // relative to the origin of the root window. | 199 // relative to the origin of the root window. |
195 gint toplevel_x = 0, toplevel_y = 0; | 200 gint toplevel_x = 0, toplevel_y = 0; |
196 gdk_window_get_position(toplevel->window, &toplevel_x, &toplevel_y); | 201 gdk_window_get_position(toplevel->window, &toplevel_x, &toplevel_y); |
197 gfx::Rect parent_rect = | 202 gfx::Rect parent_rect = |
198 gtk_util::GetWidgetRectRelativeToToplevel(parent); | 203 gtk_util::GetWidgetRectRelativeToToplevel(parent); |
199 gfx::Rect bubble_rect( | 204 gfx::Rect bubble_rect( |
200 toplevel_x + parent_rect.x() + | 205 toplevel_x + parent_rect.x() + |
201 (ltr ? 0 : parent->allocation.width - requisition.width), | 206 (ltr ? 0 : parent_allocation.width - requisition.width), |
202 toplevel_y + parent_rect.y() + | 207 toplevel_y + parent_rect.y() + |
203 parent->allocation.height - requisition.height, | 208 parent_allocation.height - requisition.height, |
204 requisition.width, | 209 requisition.width, |
205 requisition.height); | 210 requisition.height); |
206 | 211 |
207 int left_threshold = | 212 int left_threshold = |
208 bubble_rect.x() - bubble_rect.height() - kMousePadding; | 213 bubble_rect.x() - bubble_rect.height() - kMousePadding; |
209 int right_threshold = | 214 int right_threshold = |
210 bubble_rect.right() + bubble_rect.height() + kMousePadding; | 215 bubble_rect.right() + bubble_rect.height() + kMousePadding; |
211 int top_threshold = bubble_rect.y() - kMousePadding; | 216 int top_threshold = bubble_rect.y() - kMousePadding; |
212 | 217 |
213 if (((ltr && location.x() < right_threshold) || | 218 if (((ltr && location.x() < right_threshold) || |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 kCornerSize, | 326 kCornerSize, |
322 flip_horizontally ? | 327 flip_horizontally ? |
323 gtk_util::ROUNDED_TOP_LEFT : | 328 gtk_util::ROUNDED_TOP_LEFT : |
324 gtk_util::ROUNDED_TOP_RIGHT, | 329 gtk_util::ROUNDED_TOP_RIGHT, |
325 gtk_util::BORDER_TOP | | 330 gtk_util::BORDER_TOP | |
326 (flip_horizontally ? gtk_util::BORDER_LEFT : gtk_util::BORDER_RIGHT)); | 331 (flip_horizontally ? gtk_util::BORDER_LEFT : gtk_util::BORDER_RIGHT)); |
327 gtk_widget_queue_draw(container_.get()); | 332 gtk_widget_queue_draw(container_.get()); |
328 } | 333 } |
329 | 334 |
330 void StatusBubbleGtk::ExpandURL() { | 335 void StatusBubbleGtk::ExpandURL() { |
331 start_width_ = label_.get()->allocation.width; | 336 GtkAllocation allocation; |
| 337 gtk_widget_get_allocation(label_.get(), &allocation); |
| 338 start_width_ = allocation.width; |
332 expand_animation_.reset(new ui::SlideAnimation(this)); | 339 expand_animation_.reset(new ui::SlideAnimation(this)); |
333 expand_animation_->SetTweenType(ui::Tween::LINEAR); | 340 expand_animation_->SetTweenType(ui::Tween::LINEAR); |
334 expand_animation_->Show(); | 341 expand_animation_->Show(); |
335 | 342 |
336 SetStatusTextToURL(); | 343 SetStatusTextToURL(); |
337 } | 344 } |
338 | 345 |
339 void StatusBubbleGtk::UpdateLabelSizeRequest() { | 346 void StatusBubbleGtk::UpdateLabelSizeRequest() { |
340 if (!expanded() || !expand_animation_->is_animating()) { | 347 if (!expanded() || !expand_animation_->is_animating()) { |
341 gtk_widget_set_size_request(label_.get(), -1, -1); | 348 gtk_widget_set_size_request(label_.get(), -1, -1); |
(...skipping 19 matching lines...) Expand all Loading... |
361 return FALSE; | 368 return FALSE; |
362 } | 369 } |
363 | 370 |
364 void StatusBubbleGtk::AnimationEnded(const ui::Animation* animation) { | 371 void StatusBubbleGtk::AnimationEnded(const ui::Animation* animation) { |
365 UpdateLabelSizeRequest(); | 372 UpdateLabelSizeRequest(); |
366 } | 373 } |
367 | 374 |
368 void StatusBubbleGtk::AnimationProgressed(const ui::Animation* animation) { | 375 void StatusBubbleGtk::AnimationProgressed(const ui::Animation* animation) { |
369 UpdateLabelSizeRequest(); | 376 UpdateLabelSizeRequest(); |
370 } | 377 } |
OLD | NEW |