| 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 #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 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "ui/accessibility/ax_node_data.h" | 11 #include "ui/accessibility/ax_node_data.h" |
| 12 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
| 13 #include "ui/base/material_design/material_design_controller.h" | 13 #include "ui/base/material_design/material_design_controller.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
| 16 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/color_palette.h" | 17 #include "ui/gfx/color_palette.h" |
| 18 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
| 19 #include "ui/gfx/font_list.h" | 19 #include "ui/gfx/font_list.h" |
| 20 #include "ui/native_theme/native_theme.h" | 20 #include "ui/native_theme/native_theme.h" |
| 21 #include "ui/views/controls/link_listener.h" | 21 #include "ui/views/controls/link_listener.h" |
| 22 #include "ui/views/native_cursor.h" | 22 #include "ui/views/native_cursor.h" |
| 23 #include "ui/views/style/platform_style.h" |
| 23 | 24 |
| 24 namespace views { | 25 namespace views { |
| 25 | 26 |
| 26 const char Link::kViewClassName[] = "Link"; | 27 const char Link::kViewClassName[] = "Link"; |
| 27 | 28 |
| 28 Link::Link() : Link(base::string16()) {} | 29 Link::Link() : Link(base::string16()) {} |
| 29 | 30 |
| 30 Link::Link(const base::string16& title) | 31 Link::Link(const base::string16& title) |
| 31 : Label(title), | 32 : Label(title), |
| 32 requested_enabled_color_(gfx::kPlaceholderColor), | 33 requested_enabled_color_(gfx::kPlaceholderColor), |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 void Link::OnMouseCaptureLost() { | 87 void Link::OnMouseCaptureLost() { |
| 87 SetPressed(false); | 88 SetPressed(false); |
| 88 } | 89 } |
| 89 | 90 |
| 90 bool Link::OnKeyPressed(const ui::KeyEvent& event) { | 91 bool Link::OnKeyPressed(const ui::KeyEvent& event) { |
| 91 bool activate = (((event.key_code() == ui::VKEY_SPACE) && | 92 bool activate = (((event.key_code() == ui::VKEY_SPACE) && |
| 92 (event.flags() & ui::EF_ALT_DOWN) == 0) || | 93 (event.flags() & ui::EF_ALT_DOWN) == 0) || |
| 93 (event.key_code() == ui::VKEY_RETURN)); | 94 (event.key_code() == ui::VKEY_RETURN && |
| 95 PlatformStyle::kReturnClicksFocusedControl)); |
| 94 if (!activate) | 96 if (!activate) |
| 95 return false; | 97 return false; |
| 96 | 98 |
| 97 SetPressed(false); | 99 SetPressed(false); |
| 98 | 100 |
| 99 // Focus the link on key pressed. | 101 // Focus the link on key pressed. |
| 100 RequestFocus(); | 102 RequestFocus(); |
| 101 | 103 |
| 102 if (listener_) | 104 if (listener_) |
| 103 listener_->LinkClicked(this, event.flags()); | 105 listener_->LinkClicked(this, event.flags()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 116 if (listener_) | 118 if (listener_) |
| 117 listener_->LinkClicked(this, event->flags()); | 119 listener_->LinkClicked(this, event->flags()); |
| 118 } else { | 120 } else { |
| 119 SetPressed(false); | 121 SetPressed(false); |
| 120 return; | 122 return; |
| 121 } | 123 } |
| 122 event->SetHandled(); | 124 event->SetHandled(); |
| 123 } | 125 } |
| 124 | 126 |
| 125 bool Link::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 127 bool Link::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
| 126 // Make sure we don't process space or enter as accelerators. | 128 // Don't process Space and Return (depending on the platform) as an |
| 127 return (event.key_code() == ui::VKEY_SPACE) || | 129 // accelerator. |
| 128 (event.key_code() == ui::VKEY_RETURN); | 130 return event.key_code() == ui::VKEY_SPACE || |
| 131 (event.key_code() == ui::VKEY_RETURN && |
| 132 PlatformStyle::kReturnClicksFocusedControl); |
| 129 } | 133 } |
| 130 | 134 |
| 131 void Link::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 135 void Link::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 132 Label::GetAccessibleNodeData(node_data); | 136 Label::GetAccessibleNodeData(node_data); |
| 133 node_data->role = ui::AX_ROLE_LINK; | 137 node_data->role = ui::AX_ROLE_LINK; |
| 134 } | 138 } |
| 135 | 139 |
| 136 void Link::OnEnabledChanged() { | 140 void Link::OnEnabledChanged() { |
| 137 RecalculateFont(); | 141 RecalculateFont(); |
| 138 View::OnEnabledChanged(); | 142 View::OnEnabledChanged(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (GetNativeTheme()) { | 247 if (GetNativeTheme()) { |
| 244 return GetNativeTheme()->GetSystemColor( | 248 return GetNativeTheme()->GetSystemColor( |
| 245 pressed_ ? ui::NativeTheme::kColorId_LinkPressed | 249 pressed_ ? ui::NativeTheme::kColorId_LinkPressed |
| 246 : ui::NativeTheme::kColorId_LinkEnabled); | 250 : ui::NativeTheme::kColorId_LinkEnabled); |
| 247 } | 251 } |
| 248 | 252 |
| 249 return gfx::kPlaceholderColor; | 253 return gfx::kPlaceholderColor; |
| 250 } | 254 } |
| 251 | 255 |
| 252 } // namespace views | 256 } // namespace views |
| OLD | NEW |