Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: views/controls/textfield/native_textfield_views.cc

Issue 7466048: Fix RenderText cached bounds and offset logic; update clients. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comments. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/render_text.cc ('k') | views/touchui/touch_selection_controller_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 SchedulePaint(); 600 SchedulePaint();
601 } 601 }
602 602
603 void NativeTextfieldViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { 603 void NativeTextfieldViews::OnBoundsChanged(const gfx::Rect& previous_bounds) {
604 // Set the RenderText display area. 604 // Set the RenderText display area.
605 gfx::Insets insets = GetInsets(); 605 gfx::Insets insets = GetInsets();
606 gfx::Rect display_rect(insets.left(), 606 gfx::Rect display_rect(insets.left(),
607 insets.top(), 607 insets.top(),
608 width() - insets.width(), 608 width() - insets.width(),
609 height() - insets.height()); 609 height() - insets.height());
610 GetRenderText()->set_display_rect(display_rect); 610 GetRenderText()->SetDisplayRect(display_rect);
611 OnCaretBoundsChanged(); 611 OnCaretBoundsChanged();
612 } 612 }
613 613
614 /////////////////////////////////////////////////////////////////////////////// 614 ///////////////////////////////////////////////////////////////////////////////
615 // NativeTextfieldViews, TextInputClient implementation, private: 615 // NativeTextfieldViews, TextInputClient implementation, private:
616 616
617 void NativeTextfieldViews::SetCompositionText( 617 void NativeTextfieldViews::SetCompositionText(
618 const ui::CompositionText& composition) { 618 const ui::CompositionText& composition) {
619 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE) 619 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE)
620 return; 620 return;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 686
687 ui::TextInputType NativeTextfieldViews::GetTextInputType() { 687 ui::TextInputType NativeTextfieldViews::GetTextInputType() {
688 if (textfield_->read_only() || !textfield_->IsEnabled()) 688 if (textfield_->read_only() || !textfield_->IsEnabled())
689 return ui::TEXT_INPUT_TYPE_NONE; 689 return ui::TEXT_INPUT_TYPE_NONE;
690 else if (textfield_->IsPassword()) 690 else if (textfield_->IsPassword())
691 return ui::TEXT_INPUT_TYPE_PASSWORD; 691 return ui::TEXT_INPUT_TYPE_PASSWORD;
692 return ui::TEXT_INPUT_TYPE_TEXT; 692 return ui::TEXT_INPUT_TYPE_TEXT;
693 } 693 }
694 694
695 gfx::Rect NativeTextfieldViews::GetCaretBounds() { 695 gfx::Rect NativeTextfieldViews::GetCaretBounds() {
696 return GetRenderText()->CursorBounds(); 696 return GetRenderText()->GetUpdatedCursorBounds();
697 } 697 }
698 698
699 bool NativeTextfieldViews::HasCompositionText() { 699 bool NativeTextfieldViews::HasCompositionText() {
700 return model_->HasCompositionText(); 700 return model_->HasCompositionText();
701 } 701 }
702 702
703 bool NativeTextfieldViews::GetTextRange(ui::Range* range) { 703 bool NativeTextfieldViews::GetTextRange(ui::Range* range) {
704 // We don't allow the input method to retrieve or delete content from a 704 // We don't allow the input method to retrieve or delete content from a
705 // password box. 705 // password box.
706 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT) 706 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_TEXT)
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 983
984 // Notify selection controller 984 // Notify selection controller
985 if (!touch_selection_controller_.get()) 985 if (!touch_selection_controller_.get())
986 return; 986 return;
987 gfx::RenderText* render_text = GetRenderText(); 987 gfx::RenderText* render_text = GetRenderText();
988 const gfx::SelectionModel& sel = render_text->selection_model(); 988 const gfx::SelectionModel& sel = render_text->selection_model();
989 gfx::SelectionModel start_sel(sel.selection_start(), sel.selection_start(), 989 gfx::SelectionModel start_sel(sel.selection_start(), sel.selection_start(),
990 sel.selection_start(), gfx::SelectionModel::LEADING); 990 sel.selection_start(), gfx::SelectionModel::LEADING);
991 gfx::Rect start_cursor = render_text->GetCursorBounds(start_sel, false); 991 gfx::Rect start_cursor = render_text->GetCursorBounds(start_sel, false);
992 gfx::Rect end_cursor = render_text->GetCursorBounds(sel, false); 992 gfx::Rect end_cursor = render_text->GetCursorBounds(sel, false);
993 gfx::Rect display_rect = render_text->display_rect(); 993 gfx::Point start(start_cursor.x(), start_cursor.bottom());
994 int total_offset_x = display_rect.x() + render_text->display_offset().x(); 994 gfx::Point end(end_cursor.x(), end_cursor.bottom());
995 int total_offset_y = display_rect.y() + render_text->display_offset().y() +
996 (display_rect.height() - start_cursor.height()) / 2;
997 gfx::Point start(start_cursor.x() + total_offset_x,
998 start_cursor.bottom() + total_offset_y);
999 gfx::Point end(end_cursor.x() + total_offset_x,
1000 end_cursor.bottom() + total_offset_y);
1001 touch_selection_controller_->SelectionChanged(start, end); 995 touch_selection_controller_->SelectionChanged(start, end);
1002 } 996 }
1003 997
1004 void NativeTextfieldViews::OnBeforeUserAction() { 998 void NativeTextfieldViews::OnBeforeUserAction() {
1005 TextfieldController* controller = textfield_->GetController(); 999 TextfieldController* controller = textfield_->GetController();
1006 if (controller) 1000 if (controller)
1007 controller->OnBeforeUserAction(textfield_); 1001 controller->OnBeforeUserAction(textfield_);
1008 } 1002 }
1009 1003
1010 void NativeTextfieldViews::OnAfterUserAction() { 1004 void NativeTextfieldViews::OnAfterUserAction() {
(...skipping 20 matching lines...) Expand all
1031 // Filter out all control characters, including tab and new line characters, 1025 // Filter out all control characters, including tab and new line characters,
1032 // and all characters with Alt modifier. But we need to allow characters with 1026 // and all characters with Alt modifier. But we need to allow characters with
1033 // AltGr modifier. 1027 // AltGr modifier.
1034 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different 1028 // On Windows AltGr is represented by Alt+Ctrl, and on Linux it's a different
1035 // flag that we don't care about. 1029 // flag that we don't care about.
1036 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && 1030 return ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) &&
1037 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN; 1031 (flags & ~(ui::EF_SHIFT_DOWN | ui::EF_CAPS_LOCK_DOWN)) != ui::EF_ALT_DOWN;
1038 } 1032 }
1039 1033
1040 } // namespace views 1034 } // namespace views
OLDNEW
« no previous file with comments | « ui/gfx/render_text.cc ('k') | views/touchui/touch_selection_controller_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698