OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "app/gfx/font.h" | 11 #include "app/gfx/font.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 } | 54 } |
55 | 55 |
56 void Link::SetController(LinkController* controller) { | 56 void Link::SetController(LinkController* controller) { |
57 controller_ = controller; | 57 controller_ = controller; |
58 } | 58 } |
59 | 59 |
60 const LinkController* Link::GetController() { | 60 const LinkController* Link::GetController() { |
61 return controller_; | 61 return controller_; |
62 } | 62 } |
63 | 63 |
64 std::string Link::GetClassName() const { | |
65 return kViewClassName; | |
66 } | |
67 | |
68 void Link::SetHighlightedColor(const SkColor& color) { | |
69 normal_color_ = color; | |
70 ValidateStyle(); | |
71 } | |
72 | |
73 void Link::SetDisabledColor(const SkColor& color) { | |
74 disabled_color_ = color; | |
75 ValidateStyle(); | |
76 } | |
77 | |
78 void Link::SetNormalColor(const SkColor& color) { | |
79 normal_color_ = color; | |
80 ValidateStyle(); | |
81 } | |
82 | |
83 bool Link::OnMousePressed(const MouseEvent& e) { | 64 bool Link::OnMousePressed(const MouseEvent& e) { |
84 if (!enabled_ || (!e.IsLeftMouseButton() && !e.IsMiddleMouseButton())) | 65 if (!enabled_ || (!e.IsLeftMouseButton() && !e.IsMiddleMouseButton())) |
85 return false; | 66 return false; |
86 SetHighlighted(true); | 67 SetHighlighted(true); |
87 return true; | 68 return true; |
88 } | 69 } |
89 | 70 |
90 bool Link::OnMouseDragged(const MouseEvent& e) { | 71 bool Link::OnMouseDragged(const MouseEvent& e) { |
91 SetHighlighted(enabled_ && | 72 SetHighlighted(enabled_ && |
92 (e.IsLeftMouseButton() || e.IsMiddleMouseButton()) && | 73 (e.IsLeftMouseButton() || e.IsMiddleMouseButton()) && |
(...skipping 17 matching lines...) Expand all Loading... | |
110 } | 91 } |
111 | 92 |
112 bool Link::OnKeyPressed(const KeyEvent& e) { | 93 bool Link::OnKeyPressed(const KeyEvent& e) { |
113 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
114 bool activate = ((e.GetCharacter() == VK_SPACE) || | 95 bool activate = ((e.GetCharacter() == VK_SPACE) || |
115 (e.GetCharacter() == VK_RETURN)); | 96 (e.GetCharacter() == VK_RETURN)); |
116 #else | 97 #else |
117 bool activate = false; | 98 bool activate = false; |
118 NOTIMPLEMENTED(); | 99 NOTIMPLEMENTED(); |
119 #endif | 100 #endif |
120 if (activate) { | 101 if (!activate) |
121 SetHighlighted(false); | 102 return false; |
122 | 103 |
123 // Focus the link on key pressed. | 104 SetHighlighted(false); |
124 RequestFocus(); | |
125 | 105 |
126 if (controller_) | 106 // Focus the link on key pressed. |
127 controller_->LinkActivated(this, e.GetFlags()); | 107 RequestFocus(); |
128 | 108 |
129 return true; | 109 if (controller_) |
130 } | 110 controller_->LinkActivated(this, e.GetFlags()); |
131 return false; | 111 |
112 return true; | |
132 } | 113 } |
133 | 114 |
134 bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& e) { | 115 bool Link::SkipDefaultKeyEventProcessing(const KeyEvent& e) { |
135 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
136 // Make sure we don't process space or enter as accelerators. | 117 // Make sure we don't process space or enter as accelerators. |
137 return (e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN); | 118 return (e.GetCharacter() == VK_SPACE) || (e.GetCharacter() == VK_RETURN); |
138 #else | 119 #else |
139 NOTIMPLEMENTED(); | 120 NOTIMPLEMENTED(); |
140 return false; | 121 return false; |
141 #endif | 122 #endif |
142 } | 123 } |
143 | 124 |
144 void Link::SetHighlighted(bool f) { | |
145 if (f != highlighted_) { | |
146 highlighted_ = f; | |
147 ValidateStyle(); | |
148 SchedulePaint(); | |
149 } | |
150 } | |
151 | |
152 void Link::ValidateStyle() { | |
153 gfx::Font font = GetFont(); | |
154 | |
155 if (enabled_) { | |
156 if ((font.style() & gfx::Font::UNDERLINED) == 0) { | |
157 Label::SetFont(font.DeriveFont(0, font.style() | | |
158 gfx::Font::UNDERLINED)); | |
159 } | |
160 } else { | |
161 if ((font.style() & gfx::Font::UNDERLINED) != 0) { | |
162 Label::SetFont(font.DeriveFont(0, font.style() & | |
163 ~gfx::Font::UNDERLINED)); | |
164 } | |
165 } | |
166 | |
167 if (enabled_) { | |
168 if (highlighted_) { | |
169 Label::SetColor(highlighted_color_); | |
170 } else { | |
171 Label::SetColor(normal_color_); | |
172 } | |
173 } else { | |
174 Label::SetColor(disabled_color_); | |
175 } | |
176 } | |
177 | |
178 void Link::SetFont(const gfx::Font& font) { | 125 void Link::SetFont(const gfx::Font& font) { |
179 Label::SetFont(font); | 126 Label::SetFont(font); |
180 ValidateStyle(); | 127 ValidateStyle(); |
181 } | 128 } |
182 | 129 |
183 void Link::SetEnabled(bool f) { | 130 void Link::SetEnabled(bool f) { |
184 if (f != enabled_) { | 131 if (f != enabled_) { |
185 enabled_ = f; | 132 enabled_ = f; |
186 ValidateStyle(); | 133 ValidateStyle(); |
187 SchedulePaint(); | 134 SchedulePaint(); |
188 } | 135 } |
189 } | 136 } |
190 | 137 |
191 gfx::NativeCursor Link::GetCursorForPoint(Event::EventType event_type, int x, | 138 gfx::NativeCursor Link::GetCursorForPoint(Event::EventType event_type, int x, |
192 int y) { | 139 int y) { |
193 if (enabled_) { | 140 if (!enabled_) |
141 return NULL; | |
194 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
195 if (!g_hand_cursor) | 143 if (!g_hand_cursor) |
196 g_hand_cursor = LoadCursor(NULL, IDC_HAND); | 144 g_hand_cursor = LoadCursor(NULL, IDC_HAND); |
197 return g_hand_cursor; | 145 return g_hand_cursor; |
198 #elif defined(OS_LINUX) | 146 #elif defined(OS_LINUX) |
199 return gdk_cursor_new(GDK_HAND2); | 147 return gdk_cursor_new(GDK_HAND2); |
200 #endif | 148 #endif |
201 } else { | 149 } |
202 return NULL; | 150 |
151 std::string Link::GetClassName() const { | |
152 return kViewClassName; | |
153 } | |
154 | |
155 void Link::SetHighlightedColor(const SkColor& color) { | |
156 normal_color_ = color; | |
whywhat
2010/10/27 12:28:12
Is this a typo? Shouldn't be highlighted_color_ =
Peter Kasting
2010/10/27 18:23:32
If you look more closely you'll notice that I was
whywhat
2010/10/28 11:35:23
I wasn't about to blame anyone :) I just found som
| |
157 ValidateStyle(); | |
158 } | |
159 | |
160 void Link::SetDisabledColor(const SkColor& color) { | |
161 disabled_color_ = color; | |
162 ValidateStyle(); | |
163 } | |
164 | |
165 void Link::SetNormalColor(const SkColor& color) { | |
166 normal_color_ = color; | |
167 ValidateStyle(); | |
168 } | |
169 | |
170 void Link::SetHighlighted(bool f) { | |
171 if (f != highlighted_) { | |
172 highlighted_ = f; | |
173 ValidateStyle(); | |
174 SchedulePaint(); | |
203 } | 175 } |
204 } | 176 } |
205 | 177 |
178 void Link::ValidateStyle() { | |
179 gfx::Font font = GetFont(); | |
180 | |
181 if (enabled_) { | |
182 if ((font.style() & gfx::Font::UNDERLINED) == 0) | |
183 Label::SetFont(font.DeriveFont(0, font.style() | gfx::Font::UNDERLINED)); | |
184 Label::SetColor(highlighted_ ? highlighted_color_ : normal_color_); | |
185 } else { | |
186 if ((font.style() & gfx::Font::UNDERLINED) != 0) | |
187 Label::SetFont(font.DeriveFont(0, font.style() & ~gfx::Font::UNDERLINED)); | |
188 Label::SetColor(disabled_color_); | |
189 } | |
190 } | |
191 | |
206 } // namespace views | 192 } // namespace views |
OLD | NEW |