OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/views/controls/link.h" | 5 #include "ui/views/controls/link.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(TOOLKIT_USES_GTK) | 9 #if defined(TOOLKIT_USES_GTK) |
10 #include <gdk/gdk.h> | 10 #include <gdk/gdk.h> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 void Link::OnEnabledChanged() { | 45 void Link::OnEnabledChanged() { |
46 RecalculateFont(); | 46 RecalculateFont(); |
47 View::OnEnabledChanged(); | 47 View::OnEnabledChanged(); |
48 } | 48 } |
49 | 49 |
50 std::string Link::GetClassName() const { | 50 std::string Link::GetClassName() const { |
51 return kViewClassName; | 51 return kViewClassName; |
52 } | 52 } |
53 | 53 |
54 gfx::NativeCursor Link::GetCursor(const MouseEvent& event) { | 54 gfx::NativeCursor Link::GetCursor(const MouseEvent& event) { |
55 if (!IsEnabled()) | 55 if (!enabled()) |
56 return gfx::kNullCursor; | 56 return gfx::kNullCursor; |
57 #if defined(USE_AURA) | 57 #if defined(USE_AURA) |
58 return aura::kCursorHand; | 58 return aura::kCursorHand; |
59 #elif defined(OS_WIN) | 59 #elif defined(OS_WIN) |
60 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); | 60 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); |
61 return g_hand_cursor; | 61 return g_hand_cursor; |
62 #elif defined(TOOLKIT_USES_GTK) | 62 #elif defined(TOOLKIT_USES_GTK) |
63 return gfx::GetCursor(GDK_HAND2); | 63 return gfx::GetCursor(GDK_HAND2); |
64 #endif | 64 #endif |
65 } | 65 } |
66 | 66 |
67 bool Link::HitTest(const gfx::Point& l) const { | 67 bool Link::HitTest(const gfx::Point& l) const { |
68 // We need to allow clicks on the link. So we override the implementation in | 68 // We need to allow clicks on the link. So we override the implementation in |
69 // Label and use the default implementation of View. | 69 // Label and use the default implementation of View. |
70 return View::HitTest(l); | 70 return View::HitTest(l); |
71 } | 71 } |
72 | 72 |
73 bool Link::OnMousePressed(const MouseEvent& event) { | 73 bool Link::OnMousePressed(const MouseEvent& event) { |
74 if (!IsEnabled() || | 74 if (!enabled() || |
75 (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) | 75 (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) |
76 return false; | 76 return false; |
77 SetPressed(true); | 77 SetPressed(true); |
78 return true; | 78 return true; |
79 } | 79 } |
80 | 80 |
81 bool Link::OnMouseDragged(const MouseEvent& event) { | 81 bool Link::OnMouseDragged(const MouseEvent& event) { |
82 SetPressed(IsEnabled() && | 82 SetPressed(enabled() && |
83 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && | 83 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && |
84 HitTest(event.location())); | 84 HitTest(event.location())); |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 void Link::OnMouseReleased(const MouseEvent& event) { | 88 void Link::OnMouseReleased(const MouseEvent& event) { |
89 // Change the highlight first just in case this instance is deleted | 89 // Change the highlight first just in case this instance is deleted |
90 // while calling the controller | 90 // while calling the controller |
91 OnMouseCaptureLost(); | 91 OnMouseCaptureLost(); |
92 if (IsEnabled() && | 92 if (enabled() && |
93 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && | 93 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && |
94 HitTest(event.location())) { | 94 HitTest(event.location())) { |
95 // Focus the link on click. | 95 // Focus the link on click. |
96 RequestFocus(); | 96 RequestFocus(); |
97 | 97 |
98 if (listener_) | 98 if (listener_) |
99 listener_->LinkClicked(this, event.flags()); | 99 listener_->LinkClicked(this, event.flags()); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 pressed_ = pressed; | 183 pressed_ = pressed; |
184 Label::SetEnabledColor(pressed_ ? | 184 Label::SetEnabledColor(pressed_ ? |
185 requested_pressed_color_ : requested_enabled_color_); | 185 requested_pressed_color_ : requested_enabled_color_); |
186 RecalculateFont(); | 186 RecalculateFont(); |
187 SchedulePaint(); | 187 SchedulePaint(); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 void Link::RecalculateFont() { | 191 void Link::RecalculateFont() { |
192 // The font should be underlined iff the link is enabled. | 192 // The font should be underlined iff the link is enabled. |
193 if (IsEnabled() == !(font().GetStyle() & gfx::Font::UNDERLINED)) { | 193 if (enabled() == !(font().GetStyle() & gfx::Font::UNDERLINED)) { |
194 Label::SetFont(font().DeriveFont(0, IsEnabled() ? | 194 Label::SetFont(font().DeriveFont(0, enabled() ? |
195 (font().GetStyle() | gfx::Font::UNDERLINED) : | 195 (font().GetStyle() | gfx::Font::UNDERLINED) : |
196 (font().GetStyle() & ~gfx::Font::UNDERLINED))); | 196 (font().GetStyle() & ~gfx::Font::UNDERLINED))); |
197 } | 197 } |
198 } | 198 } |
199 | 199 |
200 } // namespace views | 200 } // namespace views |
OLD | NEW |