• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef UI_VIEWS_CONTROLS_LINK_H_
6 #define UI_VIEWS_CONTROLS_LINK_H_
7 
8 #include <string>
9 
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/views/controls/label.h"
12 
13 namespace views {
14 
15 class LinkListener;
16 
17 ////////////////////////////////////////////////////////////////////////////////
18 //
19 // Link class
20 //
21 // A Link is a label subclass that looks like an HTML link. It has a
22 // controller which is notified when a click occurs.
23 //
24 ////////////////////////////////////////////////////////////////////////////////
25 class VIEWS_EXPORT Link : public Label {
26  public:
27   Link();
28   explicit Link(const string16& title);
29   virtual ~Link();
30 
31   static SkColor GetDefaultEnabledColor();
32 
listener()33   const LinkListener* listener() { return listener_; }
set_listener(LinkListener * listener)34   void set_listener(LinkListener* listener) { listener_ = listener; }
35 
36   // Overridden from View:
37   virtual void OnEnabledChanged() OVERRIDE;
38   virtual const char* GetClassName() const OVERRIDE;
39   virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE;
40   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
41   virtual void OnFocus() OVERRIDE;
42   virtual void OnBlur() OVERRIDE;
43   virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
44   virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
45   virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
46   virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
47   virtual void OnMouseCaptureLost() OVERRIDE;
48   virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
49   virtual bool SkipDefaultKeyEventProcessing(
50       const ui::KeyEvent& event) OVERRIDE;
51   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
52 
53   // Overridden from ui::EventHandler:
54   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
55 
56   // Overridden from Label:
57   virtual void SetFont(const gfx::Font& font) OVERRIDE;
58 
59   virtual void SetEnabledColor(SkColor color) OVERRIDE;
60   void SetPressedColor(SkColor color);
61   void SetUnderline(bool underline);
62 
63   static const char kViewClassName[];
64 
65  private:
66   void Init();
67 
68   void SetPressed(bool pressed);
69 
70   void RecalculateFont();
71 
72   LinkListener* listener_;
73 
74   // Whether the link should be underlined when enabled.
75   bool underline_;
76 
77   // Whether the link is currently pressed.
78   bool pressed_;
79 
80   // The color when the link is neither pressed nor disabled.
81   SkColor requested_enabled_color_;
82 
83   // The color when the link is pressed.
84   SkColor requested_pressed_color_;
85 
86   DISALLOW_COPY_AND_ASSIGN(Link);
87 };
88 
89 }  // namespace views
90 
91 #endif  // UI_VIEWS_CONTROLS_LINK_H_
92