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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "ui/gfx/point.h" | 6 #include "ui/gfx/point.h" |
7 #include "ui/gfx/rect.h" | 7 #include "ui/gfx/rect.h" |
8 #include "ui/gfx/render_text.h" | 8 #include "ui/gfx/render_text.h" |
9 #include "views/controls/textfield/native_textfield_views.h" | 9 #include "views/controls/textfield/native_textfield_views.h" |
10 #include "views/controls/textfield/textfield.h" | 10 #include "views/controls/textfield/textfield.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 Widget::SetPureViews(false); | 31 Widget::SetPureViews(false); |
32 if (widget_) | 32 if (widget_) |
33 widget_->Close(); | 33 widget_->Close(); |
34 ViewsTestBase::TearDown(); | 34 ViewsTestBase::TearDown(); |
35 } | 35 } |
36 | 36 |
37 void CreateTextfield() { | 37 void CreateTextfield() { |
38 textfield_ = new Textfield(); | 38 textfield_ = new Textfield(); |
39 widget_ = new Widget; | 39 widget_ = new Widget; |
40 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); | 40 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
41 params.bounds = gfx::Rect(0, 0, 100, 100); | 41 params.bounds = gfx::Rect(0, 0, 200, 200); |
varunjain
2011/08/10 18:21:47
why is this needed?
msw
2011/08/10 18:27:44
Because with the updated code fixing the overflow
| |
42 widget_->Init(params); | 42 widget_->Init(params); |
43 View* container = new View(); | 43 View* container = new View(); |
44 widget_->SetContentsView(container); | 44 widget_->SetContentsView(container); |
45 container->AddChildView(textfield_); | 45 container->AddChildView(textfield_); |
46 | 46 |
47 textfield_view_ = static_cast<NativeTextfieldViews*>( | 47 textfield_view_ = static_cast<NativeTextfieldViews*>( |
48 textfield_->GetNativeWrapperForTesting()); | 48 textfield_->GetNativeWrapperForTesting()); |
49 textfield_view_->SetBoundsRect(params.bounds); | 49 textfield_view_->SetBoundsRect(params.bounds); |
50 textfield_->set_id(1); | 50 textfield_->set_id(1); |
51 | 51 |
52 DCHECK(textfield_view_); | 52 DCHECK(textfield_view_); |
53 textfield_->RequestFocus(); | 53 textfield_->RequestFocus(); |
54 } | 54 } |
55 | 55 |
56 protected: | 56 protected: |
57 gfx::Point GetCursorPosition(int cursor_pos) { | 57 gfx::Point GetCursorPosition(int cursor_pos) { |
58 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 58 gfx::RenderText* render_text = textfield_view_->GetRenderText(); |
59 gfx::Rect cursor_bounds = render_text->GetCursorBounds( | 59 gfx::Rect cursor_bounds = render_text->GetCursorBounds( |
60 gfx::SelectionModel(cursor_pos), false); | 60 gfx::SelectionModel(cursor_pos), false); |
61 gfx::Rect display_rect = render_text->display_rect(); | 61 return gfx::Point(cursor_bounds.x(), cursor_bounds.bottom()); |
62 int total_offset_x = display_rect.x() + render_text->display_offset().x(); | |
63 int total_offset_y = display_rect.y() + render_text->display_offset().y() + | |
64 (display_rect.height() - cursor_bounds.height()) / 2; | |
65 return gfx::Point(cursor_bounds.x() + total_offset_x, | |
66 cursor_bounds.bottom() + total_offset_y); | |
67 } | 62 } |
68 | 63 |
69 TouchSelectionControllerImpl* GetSelectionController() { | 64 TouchSelectionControllerImpl* GetSelectionController() { |
70 return static_cast<TouchSelectionControllerImpl*>( | 65 return static_cast<TouchSelectionControllerImpl*>( |
71 textfield_view_->touch_selection_controller_.get()); | 66 textfield_view_->touch_selection_controller_.get()); |
72 } | 67 } |
73 | 68 |
74 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { | 69 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { |
75 TouchSelectionControllerImpl* controller = GetSelectionController(); | 70 TouchSelectionControllerImpl* controller = GetSelectionController(); |
76 // Do the work of OnMousePressed(). | 71 // Do the work of OnMousePressed(). |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 VerifySelectionHandlePositions(true); | 175 VerifySelectionHandlePositions(true); |
181 | 176 |
182 // Drag selection handle 2 across selection handle 1. | 177 // Drag selection handle 2 across selection handle 1. |
183 x = textfield_->font().GetStringWidth(ASCIIToUTF16("with selected ")); | 178 x = textfield_->font().GetStringWidth(ASCIIToUTF16("with selected ")); |
184 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); | 179 SimulateSelectionHandleDrag(gfx::Point(x, 0), 2); |
185 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); | 180 EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected "); |
186 VerifySelectionHandlePositions(false); | 181 VerifySelectionHandlePositions(false); |
187 } | 182 } |
188 | 183 |
189 } // namespace views | 184 } // namespace views |
OLD | NEW |