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" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 enum BubbleStyle { | 131 enum BubbleStyle { |
| 132 STYLE_BOTTOM, | 132 STYLE_BOTTOM, |
| 133 STYLE_FLOATING, | 133 STYLE_FLOATING, |
| 134 STYLE_STANDARD, | 134 STYLE_STANDARD, |
| 135 STYLE_STANDARD_RIGHT | 135 STYLE_STANDARD_RIGHT |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 StatusView(views::Widget* popup, | 138 StatusView(views::Widget* popup, |
| 139 const gfx::Size& popup_size_, | 139 const gfx::Size& popup_size, |
| 140 SkColor bubble_color, | 140 const ui::ThemeProvider* theme_provider, |
| 141 SkColor bubble_text_color, | |
| 142 bool has_client_edge); | 141 bool has_client_edge); |
| 143 ~StatusView() override; | 142 ~StatusView() override; |
| 144 | 143 |
| 145 // 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 |
| 146 // an empty string. Trigger animation sequence to display if | 145 // an empty string. Trigger animation sequence to display if |
| 147 // |should_animate_open|. | 146 // |should_animate_open|. |
| 148 void SetText(const base::string16& text, bool should_animate_open); | 147 void SetText(const base::string16& text, bool should_animate_open); |
| 149 | 148 |
| 150 BubbleState state() const { return state_; } | 149 BubbleState state() const { return state_; } |
| 151 BubbleStyle style() const { return style_; } | 150 BubbleStyle style() const { return style_; } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 std::unique_ptr<StatusViewAnimation> animation_; | 193 std::unique_ptr<StatusViewAnimation> animation_; |
| 195 | 194 |
| 196 // Handle to the widget that contains us. | 195 // Handle to the widget that contains us. |
| 197 views::Widget* popup_; | 196 views::Widget* popup_; |
| 198 | 197 |
| 199 // The currently-displayed text. | 198 // The currently-displayed text. |
| 200 base::string16 text_; | 199 base::string16 text_; |
| 201 | 200 |
| 202 gfx::Size popup_size_; | 201 gfx::Size popup_size_; |
| 203 | 202 |
| 204 const SkColor bubble_color_; | 203 const ui::ThemeProvider* theme_provider_; |
| 205 const SkColor bubble_text_color_; | |
| 206 const bool has_client_edge_; | 204 const bool has_client_edge_; |
| 207 | 205 |
| 208 base::WeakPtrFactory<StatusBubbleViews::StatusView> timer_factory_; | 206 base::WeakPtrFactory<StatusBubbleViews::StatusView> timer_factory_; |
| 209 | 207 |
| 210 DISALLOW_COPY_AND_ASSIGN(StatusView); | 208 DISALLOW_COPY_AND_ASSIGN(StatusView); |
| 211 }; | 209 }; |
| 212 | 210 |
| 213 StatusBubbleViews::StatusView::StatusView(views::Widget* popup, | 211 StatusBubbleViews::StatusView::StatusView( |
| 214 const gfx::Size& popup_size, | 212 views::Widget* popup, |
| 215 SkColor bubble_color, | 213 const gfx::Size& popup_size, |
| 216 SkColor bubble_text_color, | 214 const ui::ThemeProvider* theme_provider, |
|
Peter Kasting
2016/09/24 06:07:40
So I know we're on the same page, the other soluti
Bret
2016/09/24 19:28:36
Windows does nuke the class when the theme changes
| |
| 217 bool has_client_edge) | 215 bool has_client_edge) |
| 218 : state_(BUBBLE_HIDDEN), | 216 : state_(BUBBLE_HIDDEN), |
| 219 style_(STYLE_STANDARD), | 217 style_(STYLE_STANDARD), |
| 220 animation_(new StatusViewAnimation(this, 0, 0)), | 218 animation_(new StatusViewAnimation(this, 0, 0)), |
| 221 popup_(popup), | 219 popup_(popup), |
| 222 popup_size_(popup_size), | 220 popup_size_(popup_size), |
| 223 bubble_color_(bubble_color), | 221 theme_provider_(theme_provider), |
| 224 bubble_text_color_(bubble_text_color), | |
| 225 has_client_edge_(has_client_edge), | 222 has_client_edge_(has_client_edge), |
| 226 timer_factory_(this) {} | 223 timer_factory_(this) {} |
| 227 | 224 |
| 228 StatusBubbleViews::StatusView::~StatusView() { | 225 StatusBubbleViews::StatusView::~StatusView() { |
| 229 animation_->Stop(); | 226 animation_->Stop(); |
| 230 CancelTimer(); | 227 CancelTimer(); |
| 231 } | 228 } |
| 232 | 229 |
| 233 void StatusBubbleViews::StatusView::SetText(const base::string16& text, | 230 void StatusBubbleViews::StatusView::SetText(const base::string16& text, |
| 234 bool should_animate_open) { | 231 bool should_animate_open) { |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 paint.setStrokeWidth(1); | 460 paint.setStrokeWidth(1); |
| 464 paint.setAntiAlias(true); | 461 paint.setAntiAlias(true); |
| 465 | 462 |
| 466 SkPath stroke_path; | 463 SkPath stroke_path; |
| 467 paint.getFillPath(path, &stroke_path); | 464 paint.getFillPath(path, &stroke_path); |
| 468 | 465 |
| 469 // Get the fill path by subtracting the shadow so they align neatly. | 466 // Get the fill path by subtracting the shadow so they align neatly. |
| 470 SkPath fill_path; | 467 SkPath fill_path; |
| 471 Op(path, stroke_path, kDifference_SkPathOp, &fill_path); | 468 Op(path, stroke_path, kDifference_SkPathOp, &fill_path); |
| 472 paint.setStyle(SkPaint::kFill_Style); | 469 paint.setStyle(SkPaint::kFill_Style); |
| 473 paint.setColor(bubble_color_); | 470 const SkColor bubble_color = |
| 471 theme_provider_->GetColor(ThemeProperties::COLOR_TOOLBAR); | |
| 472 paint.setColor(bubble_color); | |
| 474 canvas->sk_canvas()->drawPath(fill_path, paint); | 473 canvas->sk_canvas()->drawPath(fill_path, paint); |
| 475 | 474 |
| 476 paint.setColor(kShadowColor); | 475 paint.setColor(kShadowColor); |
| 477 canvas->sk_canvas()->drawPath(stroke_path, paint); | 476 canvas->sk_canvas()->drawPath(stroke_path, paint); |
| 478 | 477 |
| 479 canvas->Restore(); | 478 canvas->Restore(); |
| 480 | 479 |
| 481 // Compute text bounds. | 480 // Compute text bounds. |
| 482 gfx::Rect text_rect(kTextPositionX, 0, | 481 gfx::Rect text_rect(kTextPositionX, 0, |
| 483 popup_size_.width() - kTextHorizPadding, | 482 popup_size_.width() - kTextHorizPadding, |
| 484 popup_size_.height()); | 483 popup_size_.height()); |
| 485 text_rect.Inset(kShadowThickness, kShadowThickness); | 484 text_rect.Inset(kShadowThickness, kShadowThickness); |
| 486 // Make sure the text is aligned to the right on RTL UIs. | 485 // Make sure the text is aligned to the right on RTL UIs. |
| 487 text_rect.set_x(GetMirroredXForRect(text_rect)); | 486 text_rect.set_x(GetMirroredXForRect(text_rect)); |
| 488 | 487 |
| 489 // Text color is the foreground tab text color at 60% alpha. | 488 // Text color is the foreground tab text color at 60% alpha. |
| 490 SkColor blended_text_color = | 489 SkColor blended_text_color = color_utils::AlphaBlend( |
| 491 color_utils::AlphaBlend(bubble_text_color_, bubble_color_, 0x99); | 490 theme_provider_->GetColor(ThemeProperties::COLOR_TAB_TEXT), bubble_color, |
| 491 0x99); | |
| 492 canvas->DrawStringRect( | 492 canvas->DrawStringRect( |
| 493 text_, gfx::FontList(), | 493 text_, gfx::FontList(), |
| 494 color_utils::GetReadableColor(blended_text_color, bubble_color_), | 494 color_utils::GetReadableColor(blended_text_color, bubble_color), |
| 495 text_rect); | 495 text_rect); |
| 496 } | 496 } |
| 497 | 497 |
| 498 | 498 |
| 499 // StatusBubbleViews::StatusViewAnimation -------------------------------------- | 499 // StatusBubbleViews::StatusViewAnimation -------------------------------------- |
| 500 | 500 |
| 501 StatusBubbleViews::StatusViewAnimation::StatusViewAnimation( | 501 StatusBubbleViews::StatusViewAnimation::StatusViewAnimation( |
| 502 StatusView* status_view, | 502 StatusView* status_view, |
| 503 float opacity_start, | 503 float opacity_start, |
| 504 float opacity_end) | 504 float opacity_end) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 CancelExpandTimer(); | 627 CancelExpandTimer(); |
| 628 if (popup_.get()) | 628 if (popup_.get()) |
| 629 popup_->CloseNow(); | 629 popup_->CloseNow(); |
| 630 } | 630 } |
| 631 | 631 |
| 632 void StatusBubbleViews::Init() { | 632 void StatusBubbleViews::Init() { |
| 633 if (!popup_.get()) { | 633 if (!popup_.get()) { |
| 634 popup_.reset(new views::Widget); | 634 popup_.reset(new views::Widget); |
| 635 views::Widget* frame = base_view_->GetWidget(); | 635 views::Widget* frame = base_view_->GetWidget(); |
| 636 if (!view_) { | 636 if (!view_) { |
| 637 const ui::ThemeProvider* theme_provider = frame->GetThemeProvider(); | 637 view_ = new StatusView(popup_.get(), size_, frame->GetThemeProvider(), |
| 638 view_ = new StatusView( | 638 has_client_edge_); |
| 639 popup_.get(), size_, | |
| 640 theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR), | |
| 641 theme_provider->GetColor(ThemeProperties::COLOR_TAB_TEXT), | |
| 642 has_client_edge_); | |
| 643 } | 639 } |
| 644 if (!expand_view_.get()) | 640 if (!expand_view_.get()) |
| 645 expand_view_.reset(new StatusViewExpander(this, view_)); | 641 expand_view_.reset(new StatusViewExpander(this, view_)); |
| 646 | 642 |
| 647 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 643 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 648 #if defined(OS_WIN) | 644 #if defined(OS_WIN) |
| 649 // On Windows use the software compositor to ensure that we don't block | 645 // On Windows use the software compositor to ensure that we don't block |
| 650 // the UI thread blocking issue during command buffer creation. We can | 646 // the UI thread blocking issue during command buffer creation. We can |
| 651 // revert this change once http://crbug.com/125248 is fixed. | 647 // revert this change once http://crbug.com/125248 is fixed. |
| 652 params.force_software_compositing = true; | 648 params.force_software_compositing = true; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 948 void StatusBubbleViews::SetBubbleWidth(int width) { | 944 void StatusBubbleViews::SetBubbleWidth(int width) { |
| 949 size_.set_width(width); | 945 size_.set_width(width); |
| 950 SetBounds(original_position_.x(), original_position_.y(), | 946 SetBounds(original_position_.x(), original_position_.y(), |
| 951 size_.width(), size_.height()); | 947 size_.width(), size_.height()); |
| 952 } | 948 } |
| 953 | 949 |
| 954 void StatusBubbleViews::CancelExpandTimer() { | 950 void StatusBubbleViews::CancelExpandTimer() { |
| 955 if (expand_timer_factory_.HasWeakPtrs()) | 951 if (expand_timer_factory_.HasWeakPtrs()) |
| 956 expand_timer_factory_.InvalidateWeakPtrs(); | 952 expand_timer_factory_.InvalidateWeakPtrs(); |
| 957 } | 953 } |
| OLD | NEW |