Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: chrome/browser/ui/views/autofill/tooltip_icon.cc

Issue 55243005: Implement learn more bubble on views. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/autofill/tooltip_icon.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/autofill/tooltip_icon.cc
diff --git a/chrome/browser/ui/views/autofill/tooltip_icon.cc b/chrome/browser/ui/views/autofill/tooltip_icon.cc
index fba541c76d9e850d308f1ece55799b42c4881ce8..844ff5c866f5e2ca35e3d227378f9091b1dec594 100644
--- a/chrome/browser/ui/views/autofill/tooltip_icon.cc
+++ b/chrome/browser/ui/views/autofill/tooltip_icon.cc
@@ -4,18 +4,86 @@
#include "chrome/browser/ui/views/autofill/tooltip_icon.h"
+#include "base/basictypes.h"
+#include "base/timer/timer.h"
+#include "chrome/browser/ui/views/autofill/info_bubble.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/views/bubble/bubble_frame_view.h"
-TooltipIcon::TooltipIcon(const base::string16& tooltip) : tooltip_(tooltip) {
- SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed(
- IDR_AUTOFILL_TOOLTIP_ICON).ToImageSkia());
+namespace autofill {
+
+namespace {
+
+// An info bubble with some extra positioning magic for tooltip icons.
+class TooltipBubble : public InfoBubble {
+ public:
+ TooltipBubble(views::View* anchor, const base::string16& message)
+ : InfoBubble(anchor, message) {}
+ virtual ~TooltipBubble() {}
+
+ protected:
+ // InfoBubble:
+ virtual gfx::Rect GetAnchorRect() OVERRIDE {
+ gfx::Size pref_size = anchor()->GetPreferredSize();
+ gfx::Point origin = anchor()->GetBoundsInScreen().CenterPoint();
+ origin.Offset(-pref_size.width() / 2, -pref_size.height() / 2);
+ return gfx::Rect(origin, pref_size);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TooltipBubble);
+};
+
+} // namespace
+
+TooltipIcon::TooltipIcon(const base::string16& tooltip)
+ : tooltip_(tooltip),
+ bubble_(NULL) {
+ ChangeImageTo(IDR_AUTOFILL_TOOLTIP_ICON);
+}
+
+TooltipIcon::~TooltipIcon() {
+ HideBubble();
}
-TooltipIcon::~TooltipIcon() {}
+// static
+const char TooltipIcon::kViewClassName[] = "autofill/TooltipIcon";
+
+const char* TooltipIcon::GetClassName() const {
+ return TooltipIcon::kViewClassName;
+}
-bool TooltipIcon::GetTooltipText(const gfx::Point& p,
- base::string16* tooltip) const {
- *tooltip = tooltip_;
- return !tooltip_.empty();
+void TooltipIcon::OnMouseEntered(const ui::MouseEvent& event) {
+ ChangeImageTo(IDR_AUTOFILL_TOOLTIP_ICON_H);
+ ShowBubble();
}
+
+void TooltipIcon::OnMouseExited(const ui::MouseEvent& event) {
+ ChangeImageTo(IDR_AUTOFILL_TOOLTIP_ICON);
+ hide_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(250), this,
+ &TooltipIcon::HideBubble);
+}
+
+void TooltipIcon::ChangeImageTo(int idr) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ SetImage(rb.GetImageNamed(idr).ToImageSkia());
+}
+
+void TooltipIcon::ShowBubble() {
+ if (bubble_) {
+ hide_timer_.Stop();
+ } else {
+ bubble_ = new TooltipBubble(this, tooltip_);
+ bubble_->Show();
+ }
+}
+
+void TooltipIcon::HideBubble() {
+ if (bubble_) {
+ bubble_->Hide();
+ bubble_ = NULL;
+ }
+}
+
+} // namespace autofill
« no previous file with comments | « chrome/browser/ui/views/autofill/tooltip_icon.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698