| 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/textfield/native_textfield_views.h" | 5 #include "views/controls/textfield/native_textfield_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 *formats = ui::OSExchangeData::STRING; | 172 *formats = ui::OSExchangeData::STRING; |
| 173 return true; | 173 return true; |
| 174 } | 174 } |
| 175 | 175 |
| 176 bool NativeTextfieldViews::CanDrop(const OSExchangeData& data) { | 176 bool NativeTextfieldViews::CanDrop(const OSExchangeData& data) { |
| 177 return textfield_->IsEnabled() && !textfield_->read_only() && | 177 return textfield_->IsEnabled() && !textfield_->read_only() && |
| 178 data.HasString(); | 178 data.HasString(); |
| 179 } | 179 } |
| 180 | 180 |
| 181 int NativeTextfieldViews::OnDragUpdated(const DropTargetEvent& event) { | 181 int NativeTextfieldViews::OnDragUpdated(const DropTargetEvent& event) { |
| 182 // TODO(msw): retain unfocused selection, render secondary cursor... | |
| 183 DCHECK(CanDrop(event.data())); | 182 DCHECK(CanDrop(event.data())); |
| 183 bool is_point_in_selection = IsPointInSelection(event.location()); |
| 184 is_drop_cursor_visible_ = !is_point_in_selection; |
| 185 // TODO(msw): Pan over text when the user drags to the visible text edge. |
| 186 UpdateCursorBoundsAndTextOffset(FindCursorPosition(event.location()), true); |
| 187 SchedulePaint(); |
| 188 |
| 184 if (initiating_drag_) { | 189 if (initiating_drag_) { |
| 185 if (IsPointInSelection(event.location())) | 190 if (is_point_in_selection) |
| 186 return ui::DragDropTypes::DRAG_NONE; | 191 return ui::DragDropTypes::DRAG_NONE; |
| 187 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : | 192 return event.IsControlDown() ? ui::DragDropTypes::DRAG_COPY : |
| 188 ui::DragDropTypes::DRAG_MOVE; | 193 ui::DragDropTypes::DRAG_MOVE; |
| 189 } | 194 } |
| 190 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; | 195 return ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE; |
| 191 } | 196 } |
| 192 | 197 |
| 193 int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) { | 198 int NativeTextfieldViews::OnPerformDrop(const DropTargetEvent& event) { |
| 194 DCHECK(CanDrop(event.data())); | 199 DCHECK(CanDrop(event.data())); |
| 195 DCHECK(!initiating_drag_ || !IsPointInSelection(event.location())); | 200 DCHECK(!initiating_drag_ || !IsPointInSelection(event.location())); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 218 model_->InsertText(text); | 223 model_->InsertText(text); |
| 219 } | 224 } |
| 220 skip_input_method_cancel_composition_ = false; | 225 skip_input_method_cancel_composition_ = false; |
| 221 UpdateAfterChange(true, true); | 226 UpdateAfterChange(true, true); |
| 222 OnAfterUserAction(); | 227 OnAfterUserAction(); |
| 223 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; | 228 return move ? ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY; |
| 224 } | 229 } |
| 225 | 230 |
| 226 void NativeTextfieldViews::OnDragDone() { | 231 void NativeTextfieldViews::OnDragDone() { |
| 227 initiating_drag_ = false; | 232 initiating_drag_ = false; |
| 233 is_drop_cursor_visible_ = false; |
| 228 } | 234 } |
| 229 | 235 |
| 230 void NativeTextfieldViews::OnPaint(gfx::Canvas* canvas) { | 236 void NativeTextfieldViews::OnPaint(gfx::Canvas* canvas) { |
| 231 text_border_->set_has_focus(textfield_->HasFocus()); | 237 text_border_->set_has_focus(textfield_->HasFocus()); |
| 232 OnPaintBackground(canvas); | 238 OnPaintBackground(canvas); |
| 233 PaintTextAndCursor(canvas); | 239 PaintTextAndCursor(canvas); |
| 234 if (textfield_->draw_border()) | 240 if (textfield_->draw_border()) |
| 235 OnPaintBorder(canvas); | 241 OnPaintBorder(canvas); |
| 236 } | 242 } |
| 237 | 243 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 301 |
| 296 ///////////////////////////////////////////////////////////////// | 302 ///////////////////////////////////////////////////////////////// |
| 297 // NativeTextfieldViews, NativeTextifieldWrapper overrides: | 303 // NativeTextfieldViews, NativeTextifieldWrapper overrides: |
| 298 | 304 |
| 299 string16 NativeTextfieldViews::GetText() const { | 305 string16 NativeTextfieldViews::GetText() const { |
| 300 return model_->text(); | 306 return model_->text(); |
| 301 } | 307 } |
| 302 | 308 |
| 303 void NativeTextfieldViews::UpdateText() { | 309 void NativeTextfieldViews::UpdateText() { |
| 304 model_->SetText(textfield_->text()); | 310 model_->SetText(textfield_->text()); |
| 305 UpdateCursorBoundsAndTextOffset(); | 311 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 306 SchedulePaint(); | 312 SchedulePaint(); |
| 307 } | 313 } |
| 308 | 314 |
| 309 void NativeTextfieldViews::AppendText(const string16& text) { | 315 void NativeTextfieldViews::AppendText(const string16& text) { |
| 310 if (text.empty()) | 316 if (text.empty()) |
| 311 return; | 317 return; |
| 312 model_->Append(text); | 318 model_->Append(text); |
| 313 UpdateCursorBoundsAndTextOffset(); | 319 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 314 SchedulePaint(); | 320 SchedulePaint(); |
| 315 } | 321 } |
| 316 | 322 |
| 317 string16 NativeTextfieldViews::GetSelectedText() const { | 323 string16 NativeTextfieldViews::GetSelectedText() const { |
| 318 return model_->GetSelectedText(); | 324 return model_->GetSelectedText(); |
| 319 } | 325 } |
| 320 | 326 |
| 321 void NativeTextfieldViews::SelectAll() { | 327 void NativeTextfieldViews::SelectAll() { |
| 322 model_->SelectAll(); | 328 model_->SelectAll(); |
| 323 SchedulePaint(); | 329 SchedulePaint(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 349 Background::CreateSolidBackground(textfield_->background_color())); | 355 Background::CreateSolidBackground(textfield_->background_color())); |
| 350 SchedulePaint(); | 356 SchedulePaint(); |
| 351 } | 357 } |
| 352 | 358 |
| 353 void NativeTextfieldViews::UpdateReadOnly() { | 359 void NativeTextfieldViews::UpdateReadOnly() { |
| 354 SchedulePaint(); | 360 SchedulePaint(); |
| 355 OnTextInputTypeChanged(); | 361 OnTextInputTypeChanged(); |
| 356 } | 362 } |
| 357 | 363 |
| 358 void NativeTextfieldViews::UpdateFont() { | 364 void NativeTextfieldViews::UpdateFont() { |
| 359 UpdateCursorBoundsAndTextOffset(); | 365 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 360 } | 366 } |
| 361 | 367 |
| 362 void NativeTextfieldViews::UpdateIsPassword() { | 368 void NativeTextfieldViews::UpdateIsPassword() { |
| 363 model_->set_is_password(textfield_->IsPassword()); | 369 model_->set_is_password(textfield_->IsPassword()); |
| 364 UpdateCursorBoundsAndTextOffset(); | 370 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 365 SchedulePaint(); | 371 SchedulePaint(); |
| 366 OnTextInputTypeChanged(); | 372 OnTextInputTypeChanged(); |
| 367 } | 373 } |
| 368 | 374 |
| 369 void NativeTextfieldViews::UpdateEnabled() { | 375 void NativeTextfieldViews::UpdateEnabled() { |
| 370 SetEnabled(textfield_->IsEnabled()); | 376 SetEnabled(textfield_->IsEnabled()); |
| 371 SchedulePaint(); | 377 SchedulePaint(); |
| 372 OnTextInputTypeChanged(); | 378 OnTextInputTypeChanged(); |
| 373 } | 379 } |
| 374 | 380 |
| 375 gfx::Insets NativeTextfieldViews::CalculateInsets() { | 381 gfx::Insets NativeTextfieldViews::CalculateInsets() { |
| 376 return GetInsets(); | 382 return GetInsets(); |
| 377 } | 383 } |
| 378 | 384 |
| 379 void NativeTextfieldViews::UpdateHorizontalMargins() { | 385 void NativeTextfieldViews::UpdateHorizontalMargins() { |
| 380 int left, right; | 386 int left, right; |
| 381 if (!textfield_->GetHorizontalMargins(&left, &right)) | 387 if (!textfield_->GetHorizontalMargins(&left, &right)) |
| 382 return; | 388 return; |
| 383 gfx::Insets inset = GetInsets(); | 389 gfx::Insets inset = GetInsets(); |
| 384 | 390 |
| 385 text_border_->SetInsets(inset.top(), left, inset.bottom(), right); | 391 text_border_->SetInsets(inset.top(), left, inset.bottom(), right); |
| 386 UpdateCursorBoundsAndTextOffset(); | 392 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 387 } | 393 } |
| 388 | 394 |
| 389 void NativeTextfieldViews::UpdateVerticalMargins() { | 395 void NativeTextfieldViews::UpdateVerticalMargins() { |
| 390 int top, bottom; | 396 int top, bottom; |
| 391 if (!textfield_->GetVerticalMargins(&top, &bottom)) | 397 if (!textfield_->GetVerticalMargins(&top, &bottom)) |
| 392 return; | 398 return; |
| 393 gfx::Insets inset = GetInsets(); | 399 gfx::Insets inset = GetInsets(); |
| 394 | 400 |
| 395 text_border_->SetInsets(top, inset.left(), bottom, inset.right()); | 401 text_border_->SetInsets(top, inset.left(), bottom, inset.right()); |
| 396 UpdateCursorBoundsAndTextOffset(); | 402 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 397 } | 403 } |
| 398 | 404 |
| 399 bool NativeTextfieldViews::SetFocus() { | 405 bool NativeTextfieldViews::SetFocus() { |
| 400 return false; | 406 return false; |
| 401 } | 407 } |
| 402 | 408 |
| 403 View* NativeTextfieldViews::GetView() { | 409 View* NativeTextfieldViews::GetView() { |
| 404 return this; | 410 return this; |
| 405 } | 411 } |
| 406 | 412 |
| 407 gfx::NativeView NativeTextfieldViews::GetTestingHandle() const { | 413 gfx::NativeView NativeTextfieldViews::GetTestingHandle() const { |
| 408 NOTREACHED(); | 414 NOTREACHED(); |
| 409 return NULL; | 415 return NULL; |
| 410 } | 416 } |
| 411 | 417 |
| 412 bool NativeTextfieldViews::IsIMEComposing() const { | 418 bool NativeTextfieldViews::IsIMEComposing() const { |
| 413 return model_->HasCompositionText(); | 419 return model_->HasCompositionText(); |
| 414 } | 420 } |
| 415 | 421 |
| 416 void NativeTextfieldViews::GetSelectedRange(ui::Range* range) const { | 422 void NativeTextfieldViews::GetSelectedRange(ui::Range* range) const { |
| 417 model_->GetSelectedRange(range); | 423 model_->GetSelectedRange(range); |
| 418 } | 424 } |
| 419 | 425 |
| 420 void NativeTextfieldViews::SelectRange(const ui::Range& range) { | 426 void NativeTextfieldViews::SelectRange(const ui::Range& range) { |
| 421 model_->SelectRange(range); | 427 model_->SelectRange(range); |
| 422 UpdateCursorBoundsAndTextOffset(); | 428 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 423 SchedulePaint(); | 429 SchedulePaint(); |
| 424 } | 430 } |
| 425 | 431 |
| 426 size_t NativeTextfieldViews::GetCursorPosition() const { | 432 size_t NativeTextfieldViews::GetCursorPosition() const { |
| 427 return model_->cursor_pos(); | 433 return model_->cursor_pos(); |
| 428 } | 434 } |
| 429 | 435 |
| 430 bool NativeTextfieldViews::HandleKeyPressed(const KeyEvent& e) { | 436 bool NativeTextfieldViews::HandleKeyPressed(const KeyEvent& e) { |
| 431 TextfieldController* controller = textfield_->GetController(); | 437 TextfieldController* controller = textfield_->GetController(); |
| 432 bool handled = false; | 438 bool handled = false; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 return textfield_view_enabled || Widget::IsPureViews(); | 563 return textfield_view_enabled || Widget::IsPureViews(); |
| 558 #endif | 564 #endif |
| 559 } | 565 } |
| 560 | 566 |
| 561 // static | 567 // static |
| 562 void NativeTextfieldViews::SetEnableTextfieldViews(bool enabled) { | 568 void NativeTextfieldViews::SetEnableTextfieldViews(bool enabled) { |
| 563 textfield_view_enabled = enabled; | 569 textfield_view_enabled = enabled; |
| 564 } | 570 } |
| 565 | 571 |
| 566 void NativeTextfieldViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 572 void NativeTextfieldViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
| 567 UpdateCursorBoundsAndTextOffset(); | 573 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 568 } | 574 } |
| 569 | 575 |
| 570 | 576 |
| 571 /////////////////////////////////////////////////////////////////////////////// | 577 /////////////////////////////////////////////////////////////////////////////// |
| 572 // NativeTextfieldViews, TextInputClient implementation, private: | 578 // NativeTextfieldViews, TextInputClient implementation, private: |
| 573 | 579 |
| 574 void NativeTextfieldViews::SetCompositionText( | 580 void NativeTextfieldViews::SetCompositionText( |
| 575 const ui::CompositionText& composition) { | 581 const ui::CompositionText& composition) { |
| 576 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) | 582 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) |
| 577 return; | 583 return; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 cursor_timer_.NewRunnableMethod(&NativeTextfieldViews::UpdateCursor), | 760 cursor_timer_.NewRunnableMethod(&NativeTextfieldViews::UpdateCursor), |
| 755 is_cursor_visible_ ? kCursorVisibleTimeMs : kCursorInvisibleTimeMs); | 761 is_cursor_visible_ ? kCursorVisibleTimeMs : kCursorInvisibleTimeMs); |
| 756 } | 762 } |
| 757 | 763 |
| 758 void NativeTextfieldViews::RepaintCursor() { | 764 void NativeTextfieldViews::RepaintCursor() { |
| 759 gfx::Rect r = cursor_bounds_; | 765 gfx::Rect r = cursor_bounds_; |
| 760 r.Inset(-1, -1, -1, -1); | 766 r.Inset(-1, -1, -1, -1); |
| 761 SchedulePaintInRect(r); | 767 SchedulePaintInRect(r); |
| 762 } | 768 } |
| 763 | 769 |
| 764 void NativeTextfieldViews::UpdateCursorBoundsAndTextOffset() { | 770 gfx::Rect NativeTextfieldViews::GetCursorBounds(size_t cursor_pos, |
| 771 bool insert_mode) const { |
| 772 string16 text = model_->GetVisibleText(); |
| 773 const gfx::Font& font = GetFont(); |
| 774 int x = font.GetStringWidth(text.substr(0U, cursor_pos)); |
| 775 DCHECK_GE(x, 0); |
| 776 int h = std::min(height() - GetInsets().height(), font.GetHeight()); |
| 777 gfx::Rect bounds(x, (height() - h) / 2, 0, h); |
| 778 if (!insert_mode && text.length() != cursor_pos) |
| 779 bounds.set_width(font.GetStringWidth(text.substr(0, cursor_pos + 1)) - x); |
| 780 return bounds; |
| 781 } |
| 782 |
| 783 |
| 784 void NativeTextfieldViews::UpdateCursorBoundsAndTextOffset(size_t cursor_pos, |
| 785 bool insert_mode) { |
| 765 if (bounds().IsEmpty()) | 786 if (bounds().IsEmpty()) |
| 766 return; | 787 return; |
| 767 | 788 |
| 768 gfx::Insets insets = GetInsets(); | |
| 769 | |
| 770 int width = bounds().width() - insets.width(); | |
| 771 | |
| 772 // TODO(oshima): bidi | 789 // TODO(oshima): bidi |
| 773 const gfx::Font& font = GetFont(); | 790 int width = bounds().width() - GetInsets().width(); |
| 774 int full_width = font.GetStringWidth(model_->GetVisibleText()); | 791 int full_width = GetFont().GetStringWidth(model_->GetVisibleText()); |
| 775 int cursor_height = std::min(height() - insets.height(), font.GetHeight()); | 792 cursor_bounds_ = GetCursorBounds(cursor_pos, insert_mode); |
| 776 | |
| 777 cursor_bounds_ = model_->GetCursorBounds(font); | |
| 778 cursor_bounds_.set_y((height() - cursor_height) / 2); | |
| 779 cursor_bounds_.set_height(cursor_height); | |
| 780 | |
| 781 int x_right = text_offset_ + cursor_bounds_.right(); | |
| 782 int x_left = text_offset_ + cursor_bounds_.x(); | |
| 783 | 793 |
| 784 if (full_width < width) { | 794 if (full_width < width) { |
| 785 // Show all text whenever the text fits to the size. | 795 // Show all text whenever the text fits to the size. |
| 786 text_offset_ = 0; | 796 text_offset_ = 0; |
| 787 } else if (x_right > width) { | 797 } else if ((text_offset_ + cursor_bounds_.right()) > width) { |
| 788 // when the cursor overflows to the right | 798 // when the cursor overflows to the right |
| 789 text_offset_ = width - cursor_bounds_.right(); | 799 text_offset_ = width - cursor_bounds_.right(); |
| 790 } else if (x_left < 0) { | 800 } else if ((text_offset_ + cursor_bounds_.x()) < 0) { |
| 791 // when the cursor overflows to the left | 801 // when the cursor overflows to the left |
| 792 text_offset_ = -cursor_bounds_.x(); | 802 text_offset_ = -cursor_bounds_.x(); |
| 793 } else if (full_width > width && text_offset_ + full_width < width) { | 803 } else if (full_width > width && text_offset_ + full_width < width) { |
| 794 // when the cursor moves within the textfield with the text | 804 // when the cursor moves within the textfield with the text |
| 795 // longer than the field. | 805 // longer than the field. |
| 796 text_offset_ = width - full_width; | 806 text_offset_ = width - full_width; |
| 797 } else { | 807 } else { |
| 798 // move cursor freely. | 808 // move cursor freely. |
| 799 } | 809 } |
| 800 // shift cursor bounds to fit insets. | 810 // shift cursor bounds to fit insets. |
| 801 cursor_bounds_.set_x(cursor_bounds_.x() + text_offset_ + insets.left()); | 811 cursor_bounds_.set_x(cursor_bounds_.x() + text_offset_ + GetInsets().left()); |
| 802 | 812 |
| 803 OnCaretBoundsChanged(); | 813 OnCaretBoundsChanged(); |
| 804 } | 814 } |
| 805 | 815 |
| 806 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { | 816 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { |
| 807 gfx::Insets insets = GetInsets(); | 817 gfx::Insets insets = GetInsets(); |
| 808 | 818 |
| 809 canvas->Save(); | 819 canvas->Save(); |
| 810 canvas->ClipRectInt(insets.left(), insets.top(), | 820 canvas->ClipRectInt(insets.left(), insets.top(), |
| 811 width() - insets.width(), height() - insets.height()); | 821 width() - insets.width(), height() - insets.height()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 839 iter->range.end()); | 849 iter->range.end()); |
| 840 // TODO(oshima): This does not give the accurate position due to | 850 // TODO(oshima): This does not give the accurate position due to |
| 841 // kerning. Figure out how to do. | 851 // kerning. Figure out how to do. |
| 842 int width = font.GetStringWidth(text); | 852 int width = font.GetStringWidth(text); |
| 843 iter->style->DrawString(canvas, text, font, textfield_->read_only(), | 853 iter->style->DrawString(canvas, text, font, textfield_->read_only(), |
| 844 x_offset, y, width, text_height); | 854 x_offset, y, width, text_height); |
| 845 x_offset += width; | 855 x_offset += width; |
| 846 } | 856 } |
| 847 canvas->Restore(); | 857 canvas->Restore(); |
| 848 | 858 |
| 849 if (textfield_->IsEnabled() && is_cursor_visible_ && | 859 // Paint cursor. Replace cursor is drawn as rectangle for now. |
| 850 !model_->HasSelection()) { | 860 if (textfield_->IsEnabled() && (is_drop_cursor_visible_ || |
| 851 // Paint Cursor. Replace cursor is drawn as rectangle for now. | 861 (is_cursor_visible_ && !model_->HasSelection()))) |
| 852 canvas->DrawRectInt(kCursorColor, | 862 canvas->DrawRectInt(kCursorColor, |
| 853 cursor_bounds_.x(), | 863 cursor_bounds_.x(), |
| 854 cursor_bounds_.y(), | 864 cursor_bounds_.y(), |
| 855 insert_ ? 0 : cursor_bounds_.width(), | 865 cursor_bounds_.width(), |
| 856 cursor_bounds_.height()); | 866 cursor_bounds_.height()); |
| 857 } | |
| 858 } | 867 } |
| 859 | 868 |
| 860 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { | 869 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { |
| 861 // TODO(oshima): Refactor and consolidate with ExecuteCommand. | 870 // TODO(oshima): Refactor and consolidate with ExecuteCommand. |
| 862 if (key_event.type() == ui::ET_KEY_PRESSED) { | 871 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 863 ui::KeyboardCode key_code = key_event.key_code(); | 872 ui::KeyboardCode key_code = key_event.key_code(); |
| 864 // TODO(oshima): shift-tab does not work. Figure out why and fix. | 873 // TODO(oshima): shift-tab does not work. Figure out why and fix. |
| 865 if (key_code == ui::VKEY_TAB) | 874 if (key_code == ui::VKEY_TAB) |
| 866 return false; | 875 return false; |
| 867 | 876 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 bool NativeTextfieldViews::IsPointInSelection(const gfx::Point& point) const { | 1017 bool NativeTextfieldViews::IsPointInSelection(const gfx::Point& point) const { |
| 1009 ui::Range range; | 1018 ui::Range range; |
| 1010 GetSelectedRange(&range); | 1019 GetSelectedRange(&range); |
| 1011 size_t pos = FindCursorPosition(point); | 1020 size_t pos = FindCursorPosition(point); |
| 1012 return (pos >= range.GetMin() && pos < range.GetMax()); | 1021 return (pos >= range.GetMin() && pos < range.GetMax()); |
| 1013 } | 1022 } |
| 1014 | 1023 |
| 1015 bool NativeTextfieldViews::MoveCursorTo(const gfx::Point& point, bool select) { | 1024 bool NativeTextfieldViews::MoveCursorTo(const gfx::Point& point, bool select) { |
| 1016 size_t pos = FindCursorPosition(point); | 1025 size_t pos = FindCursorPosition(point); |
| 1017 if (model_->MoveCursorTo(pos, select)) { | 1026 if (model_->MoveCursorTo(pos, select)) { |
| 1018 UpdateCursorBoundsAndTextOffset(); | 1027 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 1019 return true; | 1028 return true; |
| 1020 } | 1029 } |
| 1021 return false; | 1030 return false; |
| 1022 } | 1031 } |
| 1023 | 1032 |
| 1024 void NativeTextfieldViews::PropagateTextChange() { | 1033 void NativeTextfieldViews::PropagateTextChange() { |
| 1025 textfield_->SyncText(); | 1034 textfield_->SyncText(); |
| 1026 } | 1035 } |
| 1027 | 1036 |
| 1028 void NativeTextfieldViews::UpdateAfterChange(bool text_changed, | 1037 void NativeTextfieldViews::UpdateAfterChange(bool text_changed, |
| 1029 bool cursor_changed) { | 1038 bool cursor_changed) { |
| 1030 if (text_changed) | 1039 if (text_changed) |
| 1031 PropagateTextChange(); | 1040 PropagateTextChange(); |
| 1032 if (cursor_changed) { | 1041 if (cursor_changed) { |
| 1033 is_cursor_visible_ = true; | 1042 is_cursor_visible_ = true; |
| 1034 RepaintCursor(); | 1043 RepaintCursor(); |
| 1035 } | 1044 } |
| 1036 if (text_changed || cursor_changed) { | 1045 if (text_changed || cursor_changed) { |
| 1037 UpdateCursorBoundsAndTextOffset(); | 1046 UpdateCursorBoundsAndTextOffset(model_->cursor_pos(), insert_); |
| 1038 SchedulePaint(); | 1047 SchedulePaint(); |
| 1039 } | 1048 } |
| 1040 } | 1049 } |
| 1041 | 1050 |
| 1042 void NativeTextfieldViews::UpdateContextMenu() { | 1051 void NativeTextfieldViews::UpdateContextMenu() { |
| 1043 if (!context_menu_contents_.get()) { | 1052 if (!context_menu_contents_.get()) { |
| 1044 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); | 1053 context_menu_contents_.reset(new ui::SimpleMenuModel(this)); |
| 1045 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); | 1054 context_menu_contents_->AddItemWithStringId(IDS_APP_CUT, IDS_APP_CUT); |
| 1046 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1055 context_menu_contents_->AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1047 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); | 1056 context_menu_contents_->AddItemWithStringId(IDS_APP_PASTE, IDS_APP_PASTE); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 // Filter out all control characters, including tab and new line characters, | 1110 // Filter out all control characters, including tab and new line characters, |
| 1102 // and all characters with Alt modifier. But we need to allow characters with | 1111 // and all characters with Alt modifier. But we need to allow characters with |
| 1103 // AltGr modifier. | 1112 // AltGr modifier. |
| 1104 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different | 1113 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different |
| 1105 // flag that we don't care about. | 1114 // flag that we don't care about. |
| 1106 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1115 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 1107 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; | 1116 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; |
| 1108 } | 1117 } |
| 1109 | 1118 |
| 1110 } // namespace views | 1119 } // namespace views |
| OLD | NEW |