| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/textfield/textfield.h" | 5 #include "views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 gfx::Size Textfield::GetPreferredSize() { | 254 gfx::Size Textfield::GetPreferredSize() { |
| 255 gfx::Insets insets; | 255 gfx::Insets insets; |
| 256 if (draw_border_ && native_wrapper_) | 256 if (draw_border_ && native_wrapper_) |
| 257 insets = native_wrapper_->CalculateInsets(); | 257 insets = native_wrapper_->CalculateInsets(); |
| 258 return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + | 258 return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + |
| 259 insets.width(), | 259 insets.width(), |
| 260 num_lines_ * font_.GetHeight() + insets.height()); | 260 num_lines_ * font_.GetHeight() + insets.height()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 bool Textfield::IsFocusable() const { | 263 bool Textfield::IsFocusable() const { |
| 264 return IsEnabled() && !read_only_; | 264 return View::IsFocusable() && !read_only_; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { | 267 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 268 SelectAll(); | 268 SelectAll(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) { | 271 bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) { |
| 272 // TODO(hamaji): Figure out which keyboard combinations we need to add here, | 272 // TODO(hamaji): Figure out which keyboard combinations we need to add here, |
| 273 // similar to LocationBarView::SkipDefaultKeyEventProcessing. | 273 // similar to LocationBarView::SkipDefaultKeyEventProcessing. |
| 274 app::KeyboardCode key = e.GetKeyCode(); | 274 app::KeyboardCode key = e.GetKeyCode(); |
| 275 if (key == app::VKEY_BACK) | 275 if (key == app::VKEY_BACK) |
| 276 return true; // We'll handle BackSpace ourselves. | 276 return true; // We'll handle BackSpace ourselves. |
| 277 | 277 |
| 278 #if defined(OS_WIN) | 278 #if defined(OS_WIN) |
| 279 // We don't translate accelerators for ALT + NumPad digit on Windows, they are | 279 // We don't translate accelerators for ALT + NumPad digit on Windows, they are |
| 280 // used for entering special characters. We do translate alt-home. | 280 // used for entering special characters. We do translate alt-home. |
| 281 if (e.IsAltDown() && (key != app::VKEY_HOME) && | 281 if (e.IsAltDown() && (key != app::VKEY_HOME) && |
| 282 app::win::IsNumPadDigit(key, e.IsExtendedKey())) | 282 app::win::IsNumPadDigit(key, e.IsExtendedKey())) |
| 283 return true; | 283 return true; |
| 284 #endif | 284 #endif |
| 285 return false; | 285 return false; |
| 286 } | 286 } |
| 287 | 287 |
| 288 void Textfield::PaintFocusBorder(gfx::Canvas* canvas) { | 288 void Textfield::PaintFocusBorder(gfx::Canvas* canvas) { |
| 289 if (NativeViewHost::kRenderNativeControlFocus) | 289 if (NativeViewHost::kRenderNativeControlFocus) |
| 290 View::PaintFocusBorder(canvas); | 290 View::PaintFocusBorder(canvas); |
| 291 } | 291 } |
| 292 | 292 |
| 293 bool Textfield::OnKeyPressed(const views::KeyEvent& e) { |
| 294 return native_wrapper_ && native_wrapper_->HandleKeyPressed(e); |
| 295 } |
| 296 |
| 297 bool Textfield::OnKeyReleased(const views::KeyEvent& e) { |
| 298 return native_wrapper_ && native_wrapper_->HandleKeyReleased(e); |
| 299 } |
| 300 |
| 301 void Textfield::WillGainFocus() { |
| 302 if (native_wrapper_) |
| 303 native_wrapper_->HandleWillGainFocus(); |
| 304 } |
| 305 |
| 306 void Textfield::DidGainFocus() { |
| 307 if (native_wrapper_) |
| 308 native_wrapper_->HandleDidGainFocus(); |
| 309 } |
| 310 |
| 311 void Textfield::WillLoseFocus() { |
| 312 if (native_wrapper_) |
| 313 native_wrapper_->HandleWillLoseFocus(); |
| 314 } |
| 315 |
| 293 AccessibilityTypes::Role Textfield::GetAccessibleRole() { | 316 AccessibilityTypes::Role Textfield::GetAccessibleRole() { |
| 294 return AccessibilityTypes::ROLE_TEXT; | 317 return AccessibilityTypes::ROLE_TEXT; |
| 295 } | 318 } |
| 296 | 319 |
| 297 AccessibilityTypes::State Textfield::GetAccessibleState() { | 320 AccessibilityTypes::State Textfield::GetAccessibleState() { |
| 298 int state = 0; | 321 int state = 0; |
| 299 if (read_only()) | 322 if (read_only()) |
| 300 state |= AccessibilityTypes::STATE_READONLY; | 323 state |= AccessibilityTypes::STATE_READONLY; |
| 301 if (IsPassword()) | 324 if (IsPassword()) |
| 302 state |= AccessibilityTypes::STATE_PROTECTED; | 325 state |= AccessibilityTypes::STATE_PROTECTED; |
| 303 return state; | 326 return state; |
| 304 } | 327 } |
| 305 | 328 |
| 306 std::wstring Textfield::GetAccessibleValue() { | 329 std::wstring Textfield::GetAccessibleValue() { |
| 307 if (!text_.empty()) | 330 if (!text_.empty()) |
| 308 return UTF16ToWide(text_); | 331 return UTF16ToWide(text_); |
| 309 return std::wstring(); | 332 return std::wstring(); |
| 310 } | 333 } |
| 311 | 334 |
| 312 void Textfield::SetEnabled(bool enabled) { | 335 void Textfield::SetEnabled(bool enabled) { |
| 313 View::SetEnabled(enabled); | 336 View::SetEnabled(enabled); |
| 314 if (native_wrapper_) | 337 if (native_wrapper_) |
| 315 native_wrapper_->UpdateEnabled(); | 338 native_wrapper_->UpdateEnabled(); |
| 316 } | 339 } |
| 317 | 340 |
| 318 void Textfield::Focus() { | 341 void Textfield::Focus() { |
| 319 if (native_wrapper_) { | 342 // Forward the focus to the wrapper if it exists. |
| 320 // Forward the focus to the wrapper if it exists. | 343 if (!native_wrapper_ || !native_wrapper_->SetFocus()) { |
| 321 native_wrapper_->SetFocus(); | 344 // If there is no wrapper or the wrapper din't take focus, call |
| 322 } else { | 345 // View::Focus to clear the native focus so that we still get |
| 323 // If there is no wrapper, cause the RootView to be focused so that we still | 346 // keyboard messages. |
| 324 // get keyboard messages. | |
| 325 View::Focus(); | 347 View::Focus(); |
| 326 } | 348 } |
| 327 } | 349 } |
| 328 | 350 |
| 329 void Textfield::ViewHierarchyChanged(bool is_add, View* parent, View* child) { | 351 void Textfield::ViewHierarchyChanged(bool is_add, View* parent, View* child) { |
| 330 if (is_add && !native_wrapper_ && GetWidget() && !initialized_) { | 352 if (is_add && !native_wrapper_ && GetWidget() && !initialized_) { |
| 331 initialized_ = true; | 353 initialized_ = true; |
| 332 | 354 |
| 333 // The native wrapper's lifetime will be managed by the view hierarchy after | 355 // The native wrapper's lifetime will be managed by the view hierarchy after |
| 334 // we call AddChildView. | 356 // we call AddChildView. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 348 static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); | 370 static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); |
| 349 #endif | 371 #endif |
| 350 } | 372 } |
| 351 } | 373 } |
| 352 | 374 |
| 353 std::string Textfield::GetClassName() const { | 375 std::string Textfield::GetClassName() const { |
| 354 return kViewClassName; | 376 return kViewClassName; |
| 355 } | 377 } |
| 356 | 378 |
| 357 } // namespace views | 379 } // namespace views |
| OLD | NEW |