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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/tooltip_icon.h" 5 #include "chrome/browser/ui/views/autofill/tooltip_icon.h"
6 6
7 #include "base/basictypes.h"
8 #include "base/timer/timer.h"
9 #include "chrome/browser/ui/views/autofill/info_bubble.h"
7 #include "grit/theme_resources.h" 10 #include "grit/theme_resources.h"
8 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/views/bubble/bubble_frame_view.h"
9 13
10 TooltipIcon::TooltipIcon(const base::string16& tooltip) : tooltip_(tooltip) { 14 namespace autofill {
11 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageNamed( 15
12 IDR_AUTOFILL_TOOLTIP_ICON).ToImageSkia()); 16 namespace {
17
18 // An info bubble with some extra positioning magic for tooltip icons.
19 class TooltipBubble : public InfoBubble {
20 public:
21 TooltipBubble(views::View* anchor, const base::string16& message)
22 : InfoBubble(anchor, message) {}
23 virtual ~TooltipBubble() {}
24
25 protected:
26 // InfoBubble:
27 virtual gfx::Rect GetAnchorRect() OVERRIDE {
28 gfx::Size pref_size = anchor()->GetPreferredSize();
29 gfx::Point origin = anchor()->GetBoundsInScreen().CenterPoint();
30 origin.Offset(-pref_size.width() / 2, -pref_size.height() / 2);
31 return gfx::Rect(origin, pref_size);
32 }
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(TooltipBubble);
36 };
37
38 } // namespace
39
40 TooltipIcon::TooltipIcon(const base::string16& tooltip)
41 : tooltip_(tooltip),
42 bubble_(NULL) {
43 ChangeImageTo(IDR_AUTOFILL_TOOLTIP_ICON);
13 } 44 }
14 45
15 TooltipIcon::~TooltipIcon() {} 46 TooltipIcon::~TooltipIcon() {
47 HideBubble();
48 }
16 49
17 bool TooltipIcon::GetTooltipText(const gfx::Point& p, 50 // static
18 base::string16* tooltip) const { 51 const char TooltipIcon::kViewClassName[] = "autofill/TooltipIcon";
19 *tooltip = tooltip_; 52
20 return !tooltip_.empty(); 53 const char* TooltipIcon::GetClassName() const {
54 return TooltipIcon::kViewClassName;
21 } 55 }
56
57 void TooltipIcon::OnMouseEntered(const ui::MouseEvent& event) {
58 ChangeImageTo(IDR_AUTOFILL_TOOLTIP_ICON_H);
59 ShowBubble();
60 }
61
62 void TooltipIcon::OnMouseExited(const ui::MouseEvent& event) {
63 ChangeImageTo(IDR_AUTOFILL_TOOLTIP_ICON);
64 hide_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(250), this,
65 &TooltipIcon::HideBubble);
66 }
67
68 void TooltipIcon::ChangeImageTo(int idr) {
69 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
70 SetImage(rb.GetImageNamed(idr).ToImageSkia());
71 }
72
73 void TooltipIcon::ShowBubble() {
74 if (bubble_) {
75 hide_timer_.Stop();
76 } else {
77 bubble_ = new TooltipBubble(this, tooltip_);
78 bubble_->Show();
79 }
80 }
81
82 void TooltipIcon::HideBubble() {
83 if (bubble_) {
84 bubble_->Hide();
85 bubble_ = NULL;
86 }
87 }
88
89 } // namespace autofill
OLDNEW
« 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