| 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/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "grit/ui_strings.h" | 10 #include "grit/ui_strings.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 12 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 13 #include "ui/base/cursor/cursor.h" | 13 #include "ui/base/cursor/cursor.h" |
| 14 #include "ui/base/dragdrop/drag_drop_types.h" | 14 #include "ui/base/dragdrop/drag_drop_types.h" |
| 15 #include "ui/base/dragdrop/drag_utils.h" | 15 #include "ui/base/dragdrop/drag_utils.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/base/ui_base_switches_util.h" | 17 #include "ui/base/ui_base_switches_util.h" |
| 18 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 19 #include "ui/events/keycodes/keyboard_codes.h" | 19 #include "ui/events/keycodes/keyboard_codes.h" |
| 20 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 21 #include "ui/gfx/cursor.h" |
| 21 #include "ui/gfx/display.h" | 22 #include "ui/gfx/display.h" |
| 22 #include "ui/gfx/insets.h" | 23 #include "ui/gfx/insets.h" |
| 23 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
| 24 #include "ui/native_theme/native_theme.h" | 25 #include "ui/native_theme/native_theme.h" |
| 25 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
| 26 #include "ui/views/controls/focusable_border.h" | 27 #include "ui/views/controls/focusable_border.h" |
| 27 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/menu/menu_item_view.h" | 29 #include "ui/views/controls/menu/menu_item_view.h" |
| 29 #include "ui/views/controls/menu/menu_runner.h" | 30 #include "ui/views/controls/menu/menu_runner.h" |
| 30 #include "ui/views/controls/native/native_view_host.h" | 31 #include "ui/views/controls/native/native_view_host.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 } | 483 } |
| 483 | 484 |
| 484 const char* Textfield::GetClassName() const { | 485 const char* Textfield::GetClassName() const { |
| 485 return kViewClassName; | 486 return kViewClassName; |
| 486 } | 487 } |
| 487 | 488 |
| 488 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { | 489 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { |
| 489 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); | 490 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); |
| 490 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; | 491 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; |
| 491 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); | 492 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); |
| 493 #if defined(OS_MACOSX) |
| 494 return text_cursor ? gfx::GetNativeIBeamCursor() |
| 495 : gfx::GetNativeArrowCursor(); |
| 496 #else |
| 492 return text_cursor ? ui::kCursorIBeam : ui::kCursorNull; | 497 return text_cursor ? ui::kCursorIBeam : ui::kCursorNull; |
| 498 #endif |
| 493 } | 499 } |
| 494 | |
| 495 bool Textfield::OnMousePressed(const ui::MouseEvent& event) { | 500 bool Textfield::OnMousePressed(const ui::MouseEvent& event) { |
| 496 TrackMouseClicks(event); | 501 TrackMouseClicks(event); |
| 497 | 502 |
| 498 if (!controller_ || !controller_->HandleMouseEvent(this, event)) { | 503 if (!controller_ || !controller_->HandleMouseEvent(this, event)) { |
| 499 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) { | 504 if (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) { |
| 500 RequestFocus(); | 505 RequestFocus(); |
| 501 ShowImeIfNeeded(); | 506 ShowImeIfNeeded(); |
| 502 } | 507 } |
| 503 | 508 |
| 504 if (event.IsOnlyLeftMouseButton()) { | 509 if (event.IsOnlyLeftMouseButton()) { |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 } | 917 } |
| 913 | 918 |
| 914 //////////////////////////////////////////////////////////////////////////////// | 919 //////////////////////////////////////////////////////////////////////////////// |
| 915 // Textfield, ContextMenuController overrides: | 920 // Textfield, ContextMenuController overrides: |
| 916 | 921 |
| 917 void Textfield::ShowContextMenuForView(View* source, | 922 void Textfield::ShowContextMenuForView(View* source, |
| 918 const gfx::Point& point, | 923 const gfx::Point& point, |
| 919 ui::MenuSourceType source_type) { | 924 ui::MenuSourceType source_type) { |
| 920 UpdateContextMenu(); | 925 UpdateContextMenu(); |
| 921 ignore_result(context_menu_runner_->RunMenuAt(GetWidget(), NULL, | 926 ignore_result(context_menu_runner_->RunMenuAt(GetWidget(), NULL, |
| 922 gfx::Rect(point, gfx::Size()), MenuItemView::TOPLEFT, source_type, | 927 gfx::Rect(point, gfx::Size()), ui::TOPLEFT_MENU_ANCHOR, source_type, |
| 923 MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU)); | 928 MenuRunner::HAS_MNEMONICS | MenuRunner::CONTEXT_MENU)); |
| 924 } | 929 } |
| 925 | 930 |
| 926 //////////////////////////////////////////////////////////////////////////////// | 931 //////////////////////////////////////////////////////////////////////////////// |
| 927 // Textfield, DragController overrides: | 932 // Textfield, DragController overrides: |
| 928 | 933 |
| 929 void Textfield::WriteDragDataForView(View* sender, | 934 void Textfield::WriteDragDataForView(View* sender, |
| 930 const gfx::Point& press_pt, | 935 const gfx::Point& press_pt, |
| 931 OSExchangeData* data) { | 936 OSExchangeData* data) { |
| 932 const base::string16& selected_text(GetSelectedText()); | 937 const base::string16& selected_text(GetSelectedText()); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 // [NativeWidget A] - FocusManager | 1287 // [NativeWidget A] - FocusManager |
| 1283 // [View] | 1288 // [View] |
| 1284 // [NativeWidget B] | 1289 // [NativeWidget B] |
| 1285 // [View] | 1290 // [View] |
| 1286 // [View X] | 1291 // [View X] |
| 1287 // An important thing is that [NativeWidget A] owns Win32 input focus even | 1292 // An important thing is that [NativeWidget A] owns Win32 input focus even |
| 1288 // when [View X] is logically focused by FocusManager. As a result, an Win32 | 1293 // when [View X] is logically focused by FocusManager. As a result, an Win32 |
| 1289 // IME may want to interact with the native view of [NativeWidget A] rather | 1294 // IME may want to interact with the native view of [NativeWidget A] rather |
| 1290 // than that of [NativeWidget B]. This is why we need to call | 1295 // than that of [NativeWidget B]. This is why we need to call |
| 1291 // GetTopLevelWidget() here. | 1296 // GetTopLevelWidget() here. |
| 1292 return GetWidget()->GetTopLevelWidget()->GetNativeView(); | 1297 return GetWidget()->GetTopLevelWidget()->GetNativeWindow(); |
| 1293 } | 1298 } |
| 1294 | 1299 |
| 1295 ui::TextInputType Textfield::GetTextInputType() const { | 1300 ui::TextInputType Textfield::GetTextInputType() const { |
| 1296 if (read_only() || !enabled()) | 1301 if (read_only() || !enabled()) |
| 1297 return ui::TEXT_INPUT_TYPE_NONE; | 1302 return ui::TEXT_INPUT_TYPE_NONE; |
| 1298 return text_input_type_; | 1303 return text_input_type_; |
| 1299 } | 1304 } |
| 1300 | 1305 |
| 1301 ui::TextInputMode Textfield::GetTextInputMode() const { | 1306 ui::TextInputMode Textfield::GetTextInputMode() const { |
| 1302 return ui::TEXT_INPUT_MODE_DEFAULT; | 1307 return ui::TEXT_INPUT_MODE_DEFAULT; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1673 const size_t length = selection_clipboard_text.length(); | 1678 const size_t length = selection_clipboard_text.length(); |
| 1674 range = gfx::Range(range.start() + length, range.end() + length); | 1679 range = gfx::Range(range.start() + length, range.end() + length); |
| 1675 } | 1680 } |
| 1676 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); | 1681 model_->MoveCursorTo(gfx::SelectionModel(range, affinity)); |
| 1677 UpdateAfterChange(true, true); | 1682 UpdateAfterChange(true, true); |
| 1678 OnAfterUserAction(); | 1683 OnAfterUserAction(); |
| 1679 } | 1684 } |
| 1680 } | 1685 } |
| 1681 | 1686 |
| 1682 } // namespace views | 1687 } // namespace views |
| OLD | NEW |