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 "chrome/browser/ui/views/status_bubble_views.h" | 5 #include "chrome/browser/ui/views/status_bubble_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "chrome/browser/themes/theme_properties.h" | 18 #include "chrome/browser/themes/theme_properties.h" |
| 19 #include "components/url_formatter/elide_url.h" | 19 #include "components/url_formatter/elide_url.h" |
| 20 #include "components/url_formatter/url_formatter.h" | 20 #include "components/url_formatter/url_formatter.h" |
| 21 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
| 22 #include "third_party/skia/include/core/SkRRect.h" | 22 #include "third_party/skia/include/core/SkPath.h" |
| 23 #include "third_party/skia/include/pathops/SkPathOps.h" | |
| 23 #include "ui/base/theme_provider.h" | 24 #include "ui/base/theme_provider.h" |
| 24 #include "ui/display/display.h" | 25 #include "ui/display/display.h" |
| 25 #include "ui/display/screen.h" | 26 #include "ui/display/screen.h" |
| 26 #include "ui/gfx/animation/animation_delegate.h" | 27 #include "ui/gfx/animation/animation_delegate.h" |
| 27 #include "ui/gfx/animation/linear_animation.h" | 28 #include "ui/gfx/animation/linear_animation.h" |
| 28 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
| 29 #include "ui/gfx/font_list.h" | 30 #include "ui/gfx/font_list.h" |
| 30 #include "ui/gfx/geometry/point.h" | 31 #include "ui/gfx/geometry/point.h" |
| 31 #include "ui/gfx/geometry/rect.h" | 32 #include "ui/gfx/geometry/rect.h" |
| 32 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 enum BubbleStyle { | 131 enum BubbleStyle { |
| 131 STYLE_BOTTOM, | 132 STYLE_BOTTOM, |
| 132 STYLE_FLOATING, | 133 STYLE_FLOATING, |
| 133 STYLE_STANDARD, | 134 STYLE_STANDARD, |
| 134 STYLE_STANDARD_RIGHT | 135 STYLE_STANDARD_RIGHT |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 StatusView(views::Widget* popup, | 138 StatusView(views::Widget* popup, |
| 138 const ui::ThemeProvider* theme_provider); | 139 SkColor bubble_color, |
| 140 SkColor bubble_text_color, | |
| 141 bool has_client_edge); | |
| 139 ~StatusView() override; | 142 ~StatusView() override; |
| 140 | 143 |
| 141 // Set the bubble text to a certain value, hides the bubble if text is | 144 // Set the bubble text to a certain value, hides the bubble if text is |
| 142 // an empty string. Trigger animation sequence to display if | 145 // an empty string. Trigger animation sequence to display if |
| 143 // |should_animate_open|. | 146 // |should_animate_open|. |
| 144 void SetText(const base::string16& text, bool should_animate_open); | 147 void SetText(const base::string16& text, bool should_animate_open); |
| 145 | 148 |
| 146 BubbleState state() const { return state_; } | 149 BubbleState state() const { return state_; } |
| 147 BubbleStyle style() const { return style_; } | 150 BubbleStyle style() const { return style_; } |
| 148 void SetStyle(BubbleStyle style); | 151 void SetStyle(BubbleStyle style); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 BubbleStyle style_; | 189 BubbleStyle style_; |
| 187 | 190 |
| 188 std::unique_ptr<StatusViewAnimation> animation_; | 191 std::unique_ptr<StatusViewAnimation> animation_; |
| 189 | 192 |
| 190 // Handle to the widget that contains us. | 193 // Handle to the widget that contains us. |
| 191 views::Widget* popup_; | 194 views::Widget* popup_; |
| 192 | 195 |
| 193 // The currently-displayed text. | 196 // The currently-displayed text. |
| 194 base::string16 text_; | 197 base::string16 text_; |
| 195 | 198 |
| 196 // Holds the theme provider of the frame that created us. | 199 const SkColor bubble_color_; |
| 197 const ui::ThemeProvider* theme_provider_; | 200 const SkColor bubble_text_color_; |
| 201 const bool has_client_edge_; | |
| 198 | 202 |
| 199 base::WeakPtrFactory<StatusBubbleViews::StatusView> timer_factory_; | 203 base::WeakPtrFactory<StatusBubbleViews::StatusView> timer_factory_; |
| 200 | 204 |
| 201 DISALLOW_COPY_AND_ASSIGN(StatusView); | 205 DISALLOW_COPY_AND_ASSIGN(StatusView); |
| 202 }; | 206 }; |
| 203 | 207 |
| 204 StatusBubbleViews::StatusView::StatusView( | 208 StatusBubbleViews::StatusView::StatusView(views::Widget* popup, |
| 205 views::Widget* popup, | 209 SkColor bubble_color, |
| 206 const ui::ThemeProvider* theme_provider) | 210 SkColor bubble_text_color, |
| 211 bool has_client_edge) | |
| 207 : state_(BUBBLE_HIDDEN), | 212 : state_(BUBBLE_HIDDEN), |
| 208 style_(STYLE_STANDARD), | 213 style_(STYLE_STANDARD), |
| 209 animation_(new StatusViewAnimation(this, 0, 0)), | 214 animation_(new StatusViewAnimation(this, 0, 0)), |
| 210 popup_(popup), | 215 popup_(popup), |
| 211 theme_provider_(theme_provider), | 216 bubble_color_(bubble_color), |
| 217 bubble_text_color_(bubble_text_color), | |
| 218 has_client_edge_(has_client_edge), | |
| 212 timer_factory_(this) {} | 219 timer_factory_(this) {} |
| 213 | 220 |
| 214 StatusBubbleViews::StatusView::~StatusView() { | 221 StatusBubbleViews::StatusView::~StatusView() { |
| 215 animation_->Stop(); | 222 animation_->Stop(); |
| 216 CancelTimer(); | 223 CancelTimer(); |
| 217 } | 224 } |
| 218 | 225 |
| 219 void StatusBubbleViews::StatusView::SetText(const base::string16& text, | 226 void StatusBubbleViews::StatusView::SetText(const base::string16& text, |
| 220 bool should_animate_open) { | 227 bool should_animate_open) { |
| 221 if (text.empty()) { | 228 if (text.empty()) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 } else if (state_ == BUBBLE_SHOWING_FADE) { | 366 } else if (state_ == BUBBLE_SHOWING_FADE) { |
| 360 state_ = BUBBLE_SHOWN; | 367 state_ = BUBBLE_SHOWN; |
| 361 } | 368 } |
| 362 } | 369 } |
| 363 | 370 |
| 364 const char* StatusBubbleViews::StatusView::GetClassName() const { | 371 const char* StatusBubbleViews::StatusView::GetClassName() const { |
| 365 return "StatusBubbleViews::StatusView"; | 372 return "StatusBubbleViews::StatusView"; |
| 366 } | 373 } |
| 367 | 374 |
| 368 void StatusBubbleViews::StatusView::OnPaint(gfx::Canvas* canvas) { | 375 void StatusBubbleViews::StatusView::OnPaint(gfx::Canvas* canvas) { |
| 369 SkPaint paint; | 376 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); |
| 370 paint.setStyle(SkPaint::kFill_Style); | |
| 371 paint.setAntiAlias(true); | |
| 372 SkColor toolbar_color = theme_provider_->GetColor( | |
| 373 ThemeProperties::COLOR_TOOLBAR); | |
| 374 paint.setColor(toolbar_color); | |
| 375 | 377 |
| 376 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | 378 canvas->Save(); |
| 379 float scale = canvas->UndoDeviceScaleFactor(); | |
| 380 const float radius = kBubbleCornerRadius * scale; | |
| 377 | 381 |
| 378 SkScalar rad[8] = {}; | 382 SkScalar rad[8] = {}; |
| 379 | 383 |
| 380 // Top Edges - if the bubble is in its bottom position (sticking downwards), | 384 // Top Edges - if the bubble is in its bottom position (sticking downwards), |
| 381 // then we square the top edges. Otherwise, we square the edges based on the | 385 // then we square the top edges. Otherwise, we square the edges based on the |
| 382 // position of the bubble within the window (the bubble is positioned in the | 386 // position of the bubble within the window (the bubble is positioned in the |
| 383 // southeast corner in RTL and in the southwest corner in LTR). | 387 // southeast corner in RTL and in the southwest corner in LTR). |
| 384 if (style_ != STYLE_BOTTOM) { | 388 if (style_ != STYLE_BOTTOM) { |
| 385 if (base::i18n::IsRTL() != (style_ == STYLE_STANDARD_RIGHT)) { | 389 if (base::i18n::IsRTL() != (style_ == STYLE_STANDARD_RIGHT)) { |
| 386 // The text is RtL or the bubble is on the right side (but not both). | 390 // The text is RtL or the bubble is on the right side (but not both). |
| 387 | 391 |
| 388 // Top Left corner. | 392 // Top Left corner. |
| 389 rad[0] = kBubbleCornerRadius; | 393 rad[0] = radius; |
| 390 rad[1] = kBubbleCornerRadius; | 394 rad[1] = radius; |
| 391 } else { | 395 } else { |
| 392 // Top Right corner. | 396 // Top Right corner. |
| 393 rad[2] = kBubbleCornerRadius; | 397 rad[2] = radius; |
| 394 rad[3] = kBubbleCornerRadius; | 398 rad[3] = radius; |
| 395 } | 399 } |
| 396 } | 400 } |
| 397 | 401 |
| 398 // Bottom edges - Keep these squared off if the bubble is in its standard | 402 // Bottom edges - Keep these squared off if the bubble is in its standard |
| 399 // position (sticking upward). | 403 // position (sticking upward). |
| 400 if (style_ != STYLE_STANDARD && style_ != STYLE_STANDARD_RIGHT) { | 404 if (style_ != STYLE_STANDARD && style_ != STYLE_STANDARD_RIGHT) { |
| 401 // Bottom Right Corner. | 405 // Bottom Right Corner. |
| 402 rad[4] = kBubbleCornerRadius; | 406 rad[4] = radius; |
| 403 rad[5] = kBubbleCornerRadius; | 407 rad[5] = radius; |
| 404 | 408 |
| 405 // Bottom Left Corner. | 409 // Bottom Left Corner. |
| 406 rad[6] = kBubbleCornerRadius; | 410 rad[6] = radius; |
| 407 rad[7] = kBubbleCornerRadius; | 411 rad[7] = radius; |
| 408 } | 412 } |
| 409 | 413 |
| 410 // Draw the bubble's shadow. | 414 const float width = popup_bounds.width() * scale; |
| 411 int width = popup_bounds.width(); | 415 const float height = popup_bounds.height() * scale; |
| 412 int height = popup_bounds.height(); | |
| 413 gfx::Rect rect(gfx::Rect(popup_bounds.size())); | |
| 414 SkPaint shadow_paint; | |
| 415 shadow_paint.setAntiAlias(true); | |
| 416 shadow_paint.setColor(kShadowColor); | |
| 417 | 416 |
| 418 SkRRect rrect; | 417 if (!has_client_edge_) { |
| 419 rrect.setRectRadii(RectToSkRect(rect), (const SkVector*)rad); | 418 // Clip out the edges when the bubble is docked so that it doesn't draw over |
| 420 canvas->sk_canvas()->drawRRect(rrect, shadow_paint); | 419 // the window border, since there's no client edge. But we do want the |
| 420 // border when the bubble is floating so it looks complete. | |
| 421 const int clip_left = style_ == STYLE_STANDARD ? 1 : 0; | |
| 422 const bool clip_right = style_ == STYLE_STANDARD_RIGHT ? 1 : 0; | |
| 423 const bool clip_bottom = clip_left || clip_right ? 1 : 0; | |
| 424 gfx::Rect clip_rect(clip_left, 0, width - clip_right, height - clip_bottom); | |
| 425 canvas->ClipRect(clip_rect); | |
| 426 } | |
| 421 | 427 |
| 422 const int shadow_size = 2 * kShadowThickness; | 428 // At non-integral device scale factors the size we get from |
| 423 // Draw the bubble. | 429 // GetWindowBoundsInScreen is slightly too high and the edge of our rectangle |
| 424 rect.SetRect(SkIntToScalar(kShadowThickness), SkIntToScalar(kShadowThickness), | 430 // will get clipped off. The error never seems to be more than 3 pixels. |
| 425 SkIntToScalar(width - shadow_size), | 431 const int scale_error_adjustment = scale - std::floor(scale) > 0 ? 3 : 0; |
|
Peter Kasting
2016/08/20 00:42:42
Wat.
3 px seems entirely magic. I would expect t
Bret
2016/08/24 22:04:47
It is a problem for the old code, I just got a bit
| |
| 426 SkIntToScalar(height - shadow_size)); | 432 gfx::RectF bubble_rect(width - scale_error_adjustment, height); |
| 427 rrect.setRectRadii(RectToSkRect(rect), (const SkVector*)rad); | 433 bubble_rect.Inset(0.5, 0.5); |
|
Peter Kasting
2016/08/20 00:42:42
You're still overlapping by 1 DIP in Reposition()
Bret
2016/08/24 22:04:47
Ok I misunderstood what you meant before. The rela
| |
| 428 canvas->sk_canvas()->drawRRect(rrect, paint); | 434 |
| 435 SkPath path; | |
| 436 path.addRoundRect(gfx::RectFToSkRect(bubble_rect), rad); | |
| 437 | |
| 438 SkPaint paint; | |
| 439 paint.setStyle(SkPaint::kStroke_Style); | |
| 440 paint.setStrokeWidth(1); | |
| 441 paint.setAntiAlias(true); | |
| 442 | |
| 443 SkPath stroke_path; | |
| 444 paint.getFillPath(path, &stroke_path); | |
| 445 | |
| 446 SkPath fill_path; | |
| 447 Op(path, stroke_path, kDifference_SkPathOp, &fill_path); | |
| 448 paint.setStyle(SkPaint::kFill_Style); | |
| 449 paint.setColor(bubble_color_); | |
| 450 canvas->sk_canvas()->drawPath(fill_path, paint); | |
| 451 | |
| 452 paint.setColor(kShadowColor); | |
| 453 canvas->sk_canvas()->drawPath(stroke_path, paint); | |
| 454 | |
| 455 canvas->Restore(); | |
| 429 | 456 |
| 430 // Compute text bounds. | 457 // Compute text bounds. |
| 431 const gfx::FontList font_list; | 458 gfx::Rect text_rect(popup_bounds.width() - kTextHorizPadding - |
| 432 int text_width = | 459 std::ceil(scale_error_adjustment / scale), |
| 433 std::min(gfx::GetStringWidth(text_, font_list), | 460 popup_bounds.height()); |
| 434 width - shadow_size - kTextPositionX - kTextHorizPadding); | 461 text_rect.Inset(kShadowThickness, kShadowThickness); |
| 435 int text_height = height - shadow_size; | 462 text_rect.Inset(kTextPositionX, 0); |
| 436 gfx::Rect text_bounds(kShadowThickness + kTextPositionX, | |
| 437 kShadowThickness, | |
| 438 std::max(0, text_width), | |
| 439 std::max(0, text_height)); | |
| 440 // Make sure the text is aligned to the right on RTL UIs. | 463 // Make sure the text is aligned to the right on RTL UIs. |
| 441 text_bounds.set_x(GetMirroredXForRect(text_bounds)); | 464 text_rect.set_x(GetMirroredXForRect(text_rect)); |
| 442 | 465 |
| 443 // Text color is the foreground tab text color at 60% alpha. | 466 // Text color is the foreground tab text color at 60% alpha. |
| 444 SkColor text_color = color_utils::AlphaBlend( | 467 SkColor blended_text_color = |
| 445 theme_provider_->GetColor(ThemeProperties::COLOR_TAB_TEXT), toolbar_color, | 468 color_utils::AlphaBlend(bubble_text_color_, bubble_color_, 0x99); |
| 446 0x99); | |
| 447 canvas->DrawStringRect( | 469 canvas->DrawStringRect( |
| 448 text_, font_list, | 470 text_, gfx::FontList(), |
| 449 color_utils::GetReadableColor(text_color, toolbar_color), text_bounds); | 471 color_utils::GetReadableColor(blended_text_color, bubble_color_), |
| 472 text_rect); | |
| 450 } | 473 } |
| 451 | 474 |
| 452 | 475 |
| 453 // StatusBubbleViews::StatusViewAnimation -------------------------------------- | 476 // StatusBubbleViews::StatusViewAnimation -------------------------------------- |
| 454 | 477 |
| 455 StatusBubbleViews::StatusViewAnimation::StatusViewAnimation( | 478 StatusBubbleViews::StatusViewAnimation::StatusViewAnimation( |
| 456 StatusView* status_view, | 479 StatusView* status_view, |
| 457 float opacity_start, | 480 float opacity_start, |
| 458 float opacity_end) | 481 float opacity_end) |
| 459 : gfx::LinearAnimation(kFramerate, this), | 482 : gfx::LinearAnimation(kFramerate, this), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { | 585 void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { |
| 563 status_bubble_->SetBubbleWidth(width); | 586 status_bubble_->SetBubbleWidth(width); |
| 564 status_view_->SchedulePaint(); | 587 status_view_->SchedulePaint(); |
| 565 } | 588 } |
| 566 | 589 |
| 567 | 590 |
| 568 // StatusBubbleViews ----------------------------------------------------------- | 591 // StatusBubbleViews ----------------------------------------------------------- |
| 569 | 592 |
| 570 const int StatusBubbleViews::kShadowThickness = 1; | 593 const int StatusBubbleViews::kShadowThickness = 1; |
| 571 | 594 |
| 572 StatusBubbleViews::StatusBubbleViews(views::View* base_view) | 595 StatusBubbleViews::StatusBubbleViews(views::View* base_view, |
| 596 bool has_client_edge) | |
| 573 : contains_mouse_(false), | 597 : contains_mouse_(false), |
| 574 offset_(0), | 598 offset_(0), |
| 599 has_client_edge_(has_client_edge), | |
| 575 base_view_(base_view), | 600 base_view_(base_view), |
| 576 view_(NULL), | 601 view_(NULL), |
| 577 download_shelf_is_visible_(false), | 602 download_shelf_is_visible_(false), |
| 578 is_expanded_(false), | 603 is_expanded_(false), |
| 579 expand_timer_factory_(this) { | 604 expand_timer_factory_(this) { |
| 580 expand_view_.reset(); | 605 expand_view_.reset(); |
| 581 } | 606 } |
| 582 | 607 |
| 583 StatusBubbleViews::~StatusBubbleViews() { | 608 StatusBubbleViews::~StatusBubbleViews() { |
| 584 CancelExpandTimer(); | 609 CancelExpandTimer(); |
| 585 if (popup_.get()) | 610 if (popup_.get()) |
| 586 popup_->CloseNow(); | 611 popup_->CloseNow(); |
| 587 } | 612 } |
| 588 | 613 |
| 589 void StatusBubbleViews::Init() { | 614 void StatusBubbleViews::Init() { |
| 590 if (!popup_.get()) { | 615 if (!popup_.get()) { |
| 591 popup_.reset(new views::Widget); | 616 popup_.reset(new views::Widget); |
| 592 views::Widget* frame = base_view_->GetWidget(); | 617 views::Widget* frame = base_view_->GetWidget(); |
| 593 if (!view_) | 618 if (!view_) { |
| 594 view_ = new StatusView(popup_.get(), frame->GetThemeProvider()); | 619 const ui::ThemeProvider* theme_provider = frame->GetThemeProvider(); |
| 620 view_ = new StatusView( | |
| 621 popup_.get(), | |
| 622 theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR), | |
| 623 theme_provider->GetColor(ThemeProperties::COLOR_TAB_TEXT), | |
| 624 has_client_edge_); | |
| 625 } | |
| 595 if (!expand_view_.get()) | 626 if (!expand_view_.get()) |
| 596 expand_view_.reset(new StatusViewExpander(this, view_)); | 627 expand_view_.reset(new StatusViewExpander(this, view_)); |
| 597 | 628 |
| 598 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 629 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 599 #if defined(OS_WIN) | 630 #if defined(OS_WIN) |
| 600 // On Windows use the software compositor to ensure that we don't block | 631 // On Windows use the software compositor to ensure that we don't block |
| 601 // the UI thread blocking issue during command buffer creation. We can | 632 // the UI thread blocking issue during command buffer creation. We can |
| 602 // revert this change once http://crbug.com/125248 is fixed. | 633 // revert this change once http://crbug.com/125248 is fixed. |
| 603 params.force_software_compositing = true; | 634 params.force_software_compositing = true; |
| 604 #endif | 635 #endif |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 619 popup_->SetContentsView(view_); | 650 popup_->SetContentsView(view_); |
| 620 #if defined(USE_ASH) | 651 #if defined(USE_ASH) |
| 621 ash::wm::GetWindowState(popup_->GetNativeWindow())-> | 652 ash::wm::GetWindowState(popup_->GetNativeWindow())-> |
| 622 set_ignored_by_shelf(true); | 653 set_ignored_by_shelf(true); |
| 623 #endif | 654 #endif |
| 624 RepositionPopup(); | 655 RepositionPopup(); |
| 625 } | 656 } |
| 626 } | 657 } |
| 627 | 658 |
| 628 void StatusBubbleViews::Reposition() { | 659 void StatusBubbleViews::Reposition() { |
| 629 // In restored mode, the client area has a client edge between it and the | 660 // Overlap the client edge that's shown in restored mode, or when there is no |
| 630 // frame. | 661 // client edge this makes the bubble snug with the corner of the window. |
| 631 int overlap = kShadowThickness; | 662 int overlap = kShadowThickness; |
| 632 int height = GetPreferredSize().height(); | 663 int height = GetPreferredSize().height(); |
| 633 int base_view_height = base_view()->bounds().height(); | 664 int base_view_height = base_view()->bounds().height(); |
| 634 gfx::Point origin(-overlap, base_view_height - height + overlap); | 665 gfx::Point origin(-overlap, base_view_height - height + overlap); |
| 635 SetBounds(origin.x(), origin.y(), base_view()->bounds().width() / 3, height); | 666 SetBounds(origin.x(), origin.y(), base_view()->bounds().width() / 3, height); |
| 636 } | 667 } |
| 637 | 668 |
| 638 void StatusBubbleViews::RepositionPopup() { | 669 void StatusBubbleViews::RepositionPopup() { |
| 639 if (popup_.get()) { | 670 if (popup_.get()) { |
| 640 gfx::Point top_left; | 671 gfx::Point top_left; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 | 896 |
| 866 bool StatusBubbleViews::IsFrameMaximized() { | 897 bool StatusBubbleViews::IsFrameMaximized() { |
| 867 views::Widget* frame = base_view_->GetWidget(); | 898 views::Widget* frame = base_view_->GetWidget(); |
| 868 views::Widget* window = frame->GetTopLevelWidget(); | 899 views::Widget* window = frame->GetTopLevelWidget(); |
| 869 return window && window->IsMaximized(); | 900 return window && window->IsMaximized(); |
| 870 } | 901 } |
| 871 | 902 |
| 872 void StatusBubbleViews::ExpandBubble() { | 903 void StatusBubbleViews::ExpandBubble() { |
| 873 // Elide URL to maximum possible size, then check actual length (it may | 904 // Elide URL to maximum possible size, then check actual length (it may |
| 874 // still be too long to fit) before expanding bubble. | 905 // still be too long to fit) before expanding bubble. |
| 875 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | |
| 876 int max_status_bubble_width = GetMaxStatusBubbleWidth(); | 906 int max_status_bubble_width = GetMaxStatusBubbleWidth(); |
| 877 const gfx::FontList font_list; | 907 const gfx::FontList font_list; |
| 878 url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width); | 908 url_text_ = url_formatter::ElideUrl(url_, font_list, max_status_bubble_width); |
| 879 int expanded_bubble_width = | 909 int expanded_bubble_width = |
| 880 std::max(GetStandardStatusBubbleWidth(), | 910 std::max(GetStandardStatusBubbleWidth(), |
| 881 std::min(gfx::GetStringWidth(url_text_, font_list) + | 911 std::min(gfx::GetStringWidth(url_text_, font_list) + |
| 882 (kShadowThickness * 2) + kTextPositionX + | 912 (kShadowThickness * 2) + kTextPositionX + |
| 883 kTextHorizPadding + 1, | 913 kTextHorizPadding + 1, |
| 884 max_status_bubble_width)); | 914 max_status_bubble_width)); |
| 885 is_expanded_ = true; | 915 is_expanded_ = true; |
| 916 gfx::Rect popup_bounds = popup_->GetWindowBoundsInScreen(); | |
| 886 expand_view_->StartExpansion(url_text_, popup_bounds.width(), | 917 expand_view_->StartExpansion(url_text_, popup_bounds.width(), |
| 887 expanded_bubble_width); | 918 expanded_bubble_width); |
| 888 } | 919 } |
| 889 | 920 |
| 890 int StatusBubbleViews::GetStandardStatusBubbleWidth() { | 921 int StatusBubbleViews::GetStandardStatusBubbleWidth() { |
| 891 return base_view_->bounds().width() / 3; | 922 return base_view_->bounds().width() / 3; |
| 892 } | 923 } |
| 893 | 924 |
| 894 int StatusBubbleViews::GetMaxStatusBubbleWidth() { | 925 int StatusBubbleViews::GetMaxStatusBubbleWidth() { |
| 895 const ui::NativeTheme* theme = base_view_->GetNativeTheme(); | 926 const ui::NativeTheme* theme = base_view_->GetNativeTheme(); |
| 896 return static_cast<int>(std::max(0, base_view_->bounds().width() - | 927 return static_cast<int>(std::max(0, base_view_->bounds().width() - |
| 897 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1 - | 928 (kShadowThickness * 2) - kTextPositionX - kTextHorizPadding - 1 - |
| 898 views::NativeScrollBar::GetVerticalScrollBarWidth(theme))); | 929 views::NativeScrollBar::GetVerticalScrollBarWidth(theme))); |
| 899 } | 930 } |
| 900 | 931 |
| 901 void StatusBubbleViews::SetBubbleWidth(int width) { | 932 void StatusBubbleViews::SetBubbleWidth(int width) { |
| 902 size_.set_width(width); | 933 size_.set_width(width); |
| 903 SetBounds(original_position_.x(), original_position_.y(), | 934 SetBounds(original_position_.x(), original_position_.y(), |
| 904 size_.width(), size_.height()); | 935 size_.width(), size_.height()); |
| 905 } | 936 } |
| 906 | 937 |
| 907 void StatusBubbleViews::CancelExpandTimer() { | 938 void StatusBubbleViews::CancelExpandTimer() { |
| 908 if (expand_timer_factory_.HasWeakPtrs()) | 939 if (expand_timer_factory_.HasWeakPtrs()) |
| 909 expand_timer_factory_.InvalidateWeakPtrs(); | 940 expand_timer_factory_.InvalidateWeakPtrs(); |
| 910 } | 941 } |
| OLD | NEW |