| 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 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
| 13 #include "app/l10n_util_win.h" | 13 #include "app/l10n_util_win.h" |
| 14 #endif | 14 #endif |
| 15 #include "app/animation.h" | 15 #include "app/animation.h" |
| 16 #include "app/resource_bundle.h" | 16 #include "app/resource_bundle.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "chrome/browser/browser_theme_provider.h" |
| 19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
| 21 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 22 #include "net/base/net_util.h" | 23 #include "net/base/net_util.h" |
| 23 #include "third_party/skia/include/core/SkPaint.h" | 24 #include "third_party/skia/include/core/SkPaint.h" |
| 24 #include "third_party/skia/include/core/SkPath.h" | 25 #include "third_party/skia/include/core/SkPath.h" |
| 25 #include "third_party/skia/include/core/SkRect.h" | 26 #include "third_party/skia/include/core/SkRect.h" |
| 26 #include "views/controls/label.h" | 27 #include "views/controls/label.h" |
| 27 #include "views/widget/root_view.h" | 28 #include "views/widget/root_view.h" |
| 28 #include "views/widget/widget.h" | 29 #include "views/widget/widget.h" |
| 29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 30 #include "views/widget/widget_win.h" | 31 #include "views/widget/widget_win.h" |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 // The color of the background bubble. | |
| 34 static const SkColor kBubbleColor = SkColorSetRGB(222, 234, 248); | |
| 35 | |
| 36 // The alpha and color of the bubble's shadow. | 34 // The alpha and color of the bubble's shadow. |
| 37 static const SkColor kShadowColor = SkColorSetARGB(30, 0, 0, 0); | 35 static const SkColor kShadowColor = SkColorSetARGB(30, 0, 0, 0); |
| 38 | 36 |
| 39 // The roundedness of the edges of our bubble. | 37 // The roundedness of the edges of our bubble. |
| 40 static const int kBubbleCornerRadius = 4; | 38 static const int kBubbleCornerRadius = 4; |
| 41 | 39 |
| 42 // How close the mouse can get to the infobubble before it starts sliding | 40 // How close the mouse can get to the infobubble before it starts sliding |
| 43 // off-screen. | 41 // off-screen. |
| 44 static const int kMousePadding = 20; | 42 static const int kMousePadding = 20; |
| 45 | 43 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 68 static const int kHideFadeDurationMS = 200; | 66 static const int kHideFadeDurationMS = 200; |
| 69 static const int kFramerate = 25; | 67 static const int kFramerate = 25; |
| 70 | 68 |
| 71 // View ----------------------------------------------------------------------- | 69 // View ----------------------------------------------------------------------- |
| 72 // StatusView manages the display of the bubble, applying text changes and | 70 // StatusView manages the display of the bubble, applying text changes and |
| 73 // fading in or out the bubble as required. | 71 // fading in or out the bubble as required. |
| 74 class StatusBubbleViews::StatusView : public views::Label, | 72 class StatusBubbleViews::StatusView : public views::Label, |
| 75 public Animation, | 73 public Animation, |
| 76 public AnimationDelegate { | 74 public AnimationDelegate { |
| 77 public: | 75 public: |
| 78 StatusView(StatusBubble* status_bubble, views::Widget* popup) | 76 StatusView(StatusBubble* status_bubble, views::Widget* popup, |
| 77 ThemeProvider* theme_provider) |
| 79 : Animation(kFramerate, this), | 78 : Animation(kFramerate, this), |
| 80 stage_(BUBBLE_HIDDEN), | 79 stage_(BUBBLE_HIDDEN), |
| 81 style_(STYLE_STANDARD), | 80 style_(STYLE_STANDARD), |
| 82 timer_factory_(this), | 81 timer_factory_(this), |
| 83 status_bubble_(status_bubble), | 82 status_bubble_(status_bubble), |
| 84 popup_(popup), | 83 popup_(popup), |
| 85 opacity_start_(0), | 84 opacity_start_(0), |
| 86 opacity_end_(0) { | 85 opacity_end_(0), |
| 86 theme_provider_(theme_provider) { |
| 87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 87 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 88 gfx::Font font(rb.GetFont(ResourceBundle::BaseFont)); | 88 gfx::Font font(rb.GetFont(ResourceBundle::BaseFont)); |
| 89 SetFont(font); | 89 SetFont(font); |
| 90 } | 90 } |
| 91 | 91 |
| 92 virtual ~StatusView() { | 92 virtual ~StatusView() { |
| 93 Stop(); | 93 Stop(); |
| 94 CancelTimer(); | 94 CancelTimer(); |
| 95 } | 95 } |
| 96 | 96 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 views::Widget* popup_; | 165 views::Widget* popup_; |
| 166 | 166 |
| 167 // The currently-displayed text. | 167 // The currently-displayed text. |
| 168 std::wstring text_; | 168 std::wstring text_; |
| 169 | 169 |
| 170 // Start and end opacities for the current transition - note that as a | 170 // Start and end opacities for the current transition - note that as a |
| 171 // fade-in can easily turn into a fade out, opacity_start_ is sometimes | 171 // fade-in can easily turn into a fade out, opacity_start_ is sometimes |
| 172 // a value between 0 and 1. | 172 // a value between 0 and 1. |
| 173 double opacity_start_; | 173 double opacity_start_; |
| 174 double opacity_end_; | 174 double opacity_end_; |
| 175 |
| 176 // Holds the theme provider of the frame that created us. |
| 177 ThemeProvider* theme_provider_; |
| 175 }; | 178 }; |
| 176 | 179 |
| 177 void StatusBubbleViews::StatusView::SetText(const std::wstring& text) { | 180 void StatusBubbleViews::StatusView::SetText(const std::wstring& text) { |
| 178 if (text.empty()) { | 181 if (text.empty()) { |
| 179 // The string was empty. | 182 // The string was empty. |
| 180 StartHiding(); | 183 StartHiding(); |
| 181 } else { | 184 } else { |
| 182 // We want to show the string. | 185 // We want to show the string. |
| 183 text_ = text; | 186 text_ = text; |
| 184 StartShowing(); | 187 StartShowing(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 if (style_ != style) { | 330 if (style_ != style) { |
| 328 style_ = style; | 331 style_ = style; |
| 329 SchedulePaint(); | 332 SchedulePaint(); |
| 330 } | 333 } |
| 331 } | 334 } |
| 332 | 335 |
| 333 void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { | 336 void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { |
| 334 SkPaint paint; | 337 SkPaint paint; |
| 335 paint.setStyle(SkPaint::kFill_Style); | 338 paint.setStyle(SkPaint::kFill_Style); |
| 336 paint.setFlags(SkPaint::kAntiAlias_Flag); | 339 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 337 paint.setColor(kBubbleColor); | 340 paint.setColor( |
| 341 theme_provider_->GetColor(BrowserThemeProvider::COLOR_TOOLBAR)); |
| 338 | 342 |
| 339 gfx::Rect popup_bounds; | 343 gfx::Rect popup_bounds; |
| 340 popup_->GetBounds(&popup_bounds, true); | 344 popup_->GetBounds(&popup_bounds, true); |
| 341 | 345 |
| 342 // Figure out how to round the bubble's four corners. | 346 // Figure out how to round the bubble's four corners. |
| 343 SkScalar rad[8]; | 347 SkScalar rad[8]; |
| 344 | 348 |
| 345 // Top Edges - if the bubble is in its bottom position (sticking downwards), | 349 // Top Edges - if the bubble is in its bottom position (sticking downwards), |
| 346 // then we square the top edges. Otherwise, we square the edges based on the | 350 // then we square the top edges. Otherwise, we square the edges based on the |
| 347 // position of the bubble within the window (the bubble is positioned in the | 351 // position of the bubble within the window (the bubble is positioned in the |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 popup_->CloseNow(); | 471 popup_->CloseNow(); |
| 468 } | 472 } |
| 469 | 473 |
| 470 void StatusBubbleViews::Init() { | 474 void StatusBubbleViews::Init() { |
| 471 if (!popup_.get()) { | 475 if (!popup_.get()) { |
| 472 #if defined(OS_WIN) | 476 #if defined(OS_WIN) |
| 473 views::WidgetWin* popup = new views::WidgetWin; | 477 views::WidgetWin* popup = new views::WidgetWin; |
| 474 popup->set_delete_on_destroy(false); | 478 popup->set_delete_on_destroy(false); |
| 475 | 479 |
| 476 if (!view_) | 480 if (!view_) |
| 477 view_ = new StatusView(this, popup); | 481 view_ = new StatusView(this, popup, frame_->GetThemeProvider()); |
| 478 | 482 |
| 479 popup->set_window_style(WS_POPUP); | 483 popup->set_window_style(WS_POPUP); |
| 480 popup->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | | 484 popup->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | |
| 481 WS_EX_TRANSPARENT | | 485 WS_EX_TRANSPARENT | |
| 482 l10n_util::GetExtendedTooltipStyles()); | 486 l10n_util::GetExtendedTooltipStyles()); |
| 483 popup->SetOpacity(0x00); | 487 popup->SetOpacity(0x00); |
| 484 popup->Init(frame_->GetNativeView(), gfx::Rect(), false); | 488 popup->Init(frame_->GetNativeView(), gfx::Rect(), false); |
| 485 popup->SetContentsView(view_); | 489 popup->SetContentsView(view_); |
| 486 Reposition(); | 490 Reposition(); |
| 487 popup->Show(); | 491 popup->Show(); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 } | 688 } |
| 685 } else if (offset_ != 0 || | 689 } else if (offset_ != 0 || |
| 686 view_->GetStyle() == StatusView::STYLE_STANDARD_RIGHT) { | 690 view_->GetStyle() == StatusView::STYLE_STANDARD_RIGHT) { |
| 687 offset_ = 0; | 691 offset_ = 0; |
| 688 view_->SetStyle(StatusView::STYLE_STANDARD); | 692 view_->SetStyle(StatusView::STYLE_STANDARD); |
| 689 popup_->SetBounds(gfx::Rect(top_left.x() + position_.x(), | 693 popup_->SetBounds(gfx::Rect(top_left.x() + position_.x(), |
| 690 top_left.y() + position_.y(), | 694 top_left.y() + position_.y(), |
| 691 size_.width(), size_.height())); | 695 size_.width(), size_.height())); |
| 692 } | 696 } |
| 693 } | 697 } |
| OLD | NEW |