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 "views/controls/link.h" | 5 #include "views/controls/link.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_LINUX) | 9 #if defined(OS_LINUX) |
10 #include <gdk/gdk.h> | 10 #include <gdk/gdk.h> |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 void Link::Init() { | 82 void Link::Init() { |
83 GetColors(NULL, &highlighted_color_, &disabled_color_, &normal_color_); | 83 GetColors(NULL, &highlighted_color_, &disabled_color_, &normal_color_); |
84 SetColor(normal_color_); | 84 SetColor(normal_color_); |
85 ValidateStyle(); | 85 ValidateStyle(); |
86 } | 86 } |
87 | 87 |
88 Link::~Link() { | 88 Link::~Link() { |
89 } | 89 } |
90 | 90 |
91 void Link::SetEnabled(bool flag) { | 91 void Link::OnEnabledChanged() { |
92 if (flag != enabled_) { | 92 ValidateStyle(); |
93 enabled_ = flag; | 93 View::OnEnabledChanged(); |
94 ValidateStyle(); | |
95 SchedulePaint(); | |
96 } | |
97 } | 94 } |
98 | 95 |
99 std::string Link::GetClassName() const { | 96 std::string Link::GetClassName() const { |
100 return kViewClassName; | 97 return kViewClassName; |
101 } | 98 } |
102 | 99 |
103 gfx::NativeCursor Link::GetCursor(const MouseEvent& event) { | 100 gfx::NativeCursor Link::GetCursor(const MouseEvent& event) { |
104 if (!enabled_) | 101 if (!IsEnabled()) |
105 return NULL; | 102 return NULL; |
106 #if defined(OS_WIN) | 103 #if defined(OS_WIN) |
107 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); | 104 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); |
108 return g_hand_cursor; | 105 return g_hand_cursor; |
109 #elif defined(OS_LINUX) | 106 #elif defined(OS_LINUX) |
110 return gfx::GetCursor(GDK_HAND2); | 107 return gfx::GetCursor(GDK_HAND2); |
111 #endif | 108 #endif |
112 } | 109 } |
113 | 110 |
114 bool Link::OnMousePressed(const MouseEvent& event) { | 111 bool Link::OnMousePressed(const MouseEvent& event) { |
115 if (!enabled_ || (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) | 112 if (!IsEnabled() || |
| 113 (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) |
116 return false; | 114 return false; |
117 SetHighlighted(true); | 115 SetHighlighted(true); |
118 return true; | 116 return true; |
119 } | 117 } |
120 | 118 |
121 bool Link::OnMouseDragged(const MouseEvent& event) { | 119 bool Link::OnMouseDragged(const MouseEvent& event) { |
122 SetHighlighted(enabled_ && | 120 SetHighlighted(IsEnabled() && |
123 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && | 121 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && |
124 HitTest(event.location())); | 122 HitTest(event.location())); |
125 return true; | 123 return true; |
126 } | 124 } |
127 | 125 |
128 void Link::OnMouseReleased(const MouseEvent& event) { | 126 void Link::OnMouseReleased(const MouseEvent& event) { |
129 // Change the highlight first just in case this instance is deleted | 127 // Change the highlight first just in case this instance is deleted |
130 // while calling the controller | 128 // while calling the controller |
131 OnMouseCaptureLost(); | 129 OnMouseCaptureLost(); |
132 if (enabled_ && (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && | 130 if (IsEnabled() && |
| 131 (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && |
133 HitTest(event.location())) { | 132 HitTest(event.location())) { |
134 // Focus the link on click. | 133 // Focus the link on click. |
135 RequestFocus(); | 134 RequestFocus(); |
136 | 135 |
137 if (listener_) | 136 if (listener_) |
138 listener_->LinkClicked(this, event.flags()); | 137 listener_->LinkClicked(this, event.flags()); |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 void Link::OnMouseCaptureLost() { | 141 void Link::OnMouseCaptureLost() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 197 |
199 void Link::SetHighlighted(bool f) { | 198 void Link::SetHighlighted(bool f) { |
200 if (f != highlighted_) { | 199 if (f != highlighted_) { |
201 highlighted_ = f; | 200 highlighted_ = f; |
202 ValidateStyle(); | 201 ValidateStyle(); |
203 SchedulePaint(); | 202 SchedulePaint(); |
204 } | 203 } |
205 } | 204 } |
206 | 205 |
207 void Link::ValidateStyle() { | 206 void Link::ValidateStyle() { |
208 if (enabled_) { | 207 if (IsEnabled()) { |
209 if (!(font().GetStyle() & gfx::Font::UNDERLINED)) { | 208 if (!(font().GetStyle() & gfx::Font::UNDERLINED)) { |
210 Label::SetFont( | 209 Label::SetFont( |
211 font().DeriveFont(0, font().GetStyle() | gfx::Font::UNDERLINED)); | 210 font().DeriveFont(0, font().GetStyle() | gfx::Font::UNDERLINED)); |
212 } | 211 } |
213 Label::SetColor(highlighted_ ? highlighted_color_ : normal_color_); | 212 Label::SetColor(highlighted_ ? highlighted_color_ : normal_color_); |
214 } else { | 213 } else { |
215 if (font().GetStyle() & gfx::Font::UNDERLINED) { | 214 if (font().GetStyle() & gfx::Font::UNDERLINED) { |
216 Label::SetFont( | 215 Label::SetFont( |
217 font().DeriveFont(0, font().GetStyle() & ~gfx::Font::UNDERLINED)); | 216 font().DeriveFont(0, font().GetStyle() & ~gfx::Font::UNDERLINED)); |
218 } | 217 } |
219 Label::SetColor(disabled_color_); | 218 Label::SetColor(disabled_color_); |
220 } | 219 } |
221 } | 220 } |
222 | 221 |
223 } // namespace views | 222 } // namespace views |
OLD | NEW |