| 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 #ifndef UI_VIEWS_CONTROLS_LINK_H_ | 5 #ifndef UI_VIEWS_CONTROLS_LINK_H_ |
| 6 #define UI_VIEWS_CONTROLS_LINK_H_ | 6 #define UI_VIEWS_CONTROLS_LINK_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/views/controls/label.h" | 12 #include "ui/views/controls/label.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 | 15 |
| 16 class LinkListener; | 16 class LinkListener; |
| 17 | 17 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 19 // | 19 // |
| 20 // Link class | 20 // Link class |
| 21 // | 21 // |
| 22 // A Link is a label subclass that looks like an HTML link. It has a | 22 // A Link is a label subclass that looks like an HTML link. It has a |
| 23 // controller which is notified when a click occurs. | 23 // controller which is notified when a click occurs. |
| 24 // | 24 // |
| 25 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
| 26 class VIEWS_EXPORT Link : public Label { | 26 class VIEWS_EXPORT Link : public Label { |
| 27 public: | 27 public: |
| 28 static const char kViewClassName[]; |
| 29 |
| 30 // The padding for the focus ring border when rendering a focused Link with |
| 31 // FocusStyle::RING. |
| 32 static constexpr int kFocusBorderPadding = 1; |
| 33 |
| 34 // How the Link is styled when focused. |
| 35 enum class FocusStyle { |
| 36 UNDERLINE, // An underline style is added to the text only when focused. |
| 37 RING, // A focus ring is drawn around the View. |
| 38 }; |
| 39 |
| 28 Link(); | 40 Link(); |
| 29 explicit Link(const base::string16& title); | 41 explicit Link(const base::string16& title); |
| 30 ~Link() override; | 42 ~Link() override; |
| 31 | 43 |
| 44 // Returns the default FocusStyle for a views::Link. Calling SetUnderline() |
| 45 // may change it: E.g. SetUnderline(true) forces FocusStyle::RING. |
| 46 static FocusStyle GetDefaultFocusStyle(); |
| 47 |
| 48 // Returns the current FocusStyle of this Link. |
| 49 FocusStyle GetFocusStyle() const; |
| 50 |
| 32 const LinkListener* listener() { return listener_; } | 51 const LinkListener* listener() { return listener_; } |
| 33 void set_listener(LinkListener* listener) { listener_ = listener; } | 52 void set_listener(LinkListener* listener) { listener_ = listener; } |
| 34 | 53 |
| 35 // Label: | 54 // Label: |
| 55 void PaintFocusRing(gfx::Canvas* canvas) const override; |
| 56 gfx::Insets GetInsets() const override; |
| 36 const char* GetClassName() const override; | 57 const char* GetClassName() const override; |
| 37 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; | 58 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; |
| 38 bool CanProcessEventsWithinSubtree() const override; | 59 bool CanProcessEventsWithinSubtree() const override; |
| 39 bool OnMousePressed(const ui::MouseEvent& event) override; | 60 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 40 bool OnMouseDragged(const ui::MouseEvent& event) override; | 61 bool OnMouseDragged(const ui::MouseEvent& event) override; |
| 41 void OnMouseReleased(const ui::MouseEvent& event) override; | 62 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 42 void OnMouseCaptureLost() override; | 63 void OnMouseCaptureLost() override; |
| 43 bool OnKeyPressed(const ui::KeyEvent& event) override; | 64 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 44 void OnGestureEvent(ui::GestureEvent* event) override; | 65 void OnGestureEvent(ui::GestureEvent* event) override; |
| 45 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override; | 66 bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) override; |
| 46 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 67 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 47 void OnEnabledChanged() override; | 68 void OnEnabledChanged() override; |
| 48 void OnFocus() override; | 69 void OnFocus() override; |
| 49 void OnBlur() override; | 70 void OnBlur() override; |
| 50 void SetFontList(const gfx::FontList& font_list) override; | 71 void SetFontList(const gfx::FontList& font_list) override; |
| 51 void SetText(const base::string16& text) override; | 72 void SetText(const base::string16& text) override; |
| 52 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 73 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 53 void SetEnabledColor(SkColor color) override; | 74 void SetEnabledColor(SkColor color) override; |
| 54 bool IsSelectionSupported() const override; | 75 bool IsSelectionSupported() const override; |
| 55 | 76 |
| 56 // TODO(estade): almost all the places that call this pass false. With | 77 // TODO(estade): almost all the places that call this pass false. With |
| 57 // Harmony, false is already the default so those callsites can be removed. | 78 // Harmony, false is already the default so those callsites can be removed. |
| 79 // TODO(tapted): Then remove all callsites when client code sets a correct |
| 80 // typography style and derives this from style::GetFont(STYLE_LINK). |
| 58 void SetUnderline(bool underline); | 81 void SetUnderline(bool underline); |
| 59 | 82 |
| 60 static const char kViewClassName[]; | |
| 61 | |
| 62 private: | 83 private: |
| 63 void Init(); | 84 void Init(); |
| 64 | 85 |
| 65 void SetPressed(bool pressed); | 86 void SetPressed(bool pressed); |
| 66 | 87 |
| 67 void RecalculateFont(); | 88 void RecalculateFont(); |
| 68 | 89 |
| 69 void ConfigureFocus(); | 90 void ConfigureFocus(); |
| 70 | 91 |
| 71 SkColor GetEnabledColor(); | 92 SkColor GetEnabledColor(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 86 // The color when the link is pressed. | 107 // The color when the link is pressed. |
| 87 SkColor requested_pressed_color_; | 108 SkColor requested_pressed_color_; |
| 88 bool requested_pressed_color_set_; | 109 bool requested_pressed_color_set_; |
| 89 | 110 |
| 90 DISALLOW_COPY_AND_ASSIGN(Link); | 111 DISALLOW_COPY_AND_ASSIGN(Link); |
| 91 }; | 112 }; |
| 92 | 113 |
| 93 } // namespace views | 114 } // namespace views |
| 94 | 115 |
| 95 #endif // UI_VIEWS_CONTROLS_LINK_H_ | 116 #endif // UI_VIEWS_CONTROLS_LINK_H_ |
| OLD | NEW |