| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/prefix_selector.h" | 5 #include "ui/views/controls/prefix_selector.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "ui/base/ime/input_method.h" | 8 #include "ui/base/ime/input_method.h" |
| 9 #include "ui/base/ime/text_input_type.h" | 9 #include "ui/base/ime/text_input_type.h" |
| 10 #include "ui/gfx/range/range.h" | 10 #include "ui/gfx/range/range.h" |
| 11 #include "ui/views/controls/prefix_delegate.h" | 11 #include "ui/views/controls/prefix_delegate.h" |
| 12 #include "ui/views/view.h" |
| 12 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const int64_t kTimeBeforeClearingMS = 1000; | 19 const int64_t kTimeBeforeClearingMS = 1000; |
| 19 | 20 |
| 20 void ConvertRectToScreen(const views::View* src, gfx::Rect* r) { | 21 void ConvertRectToScreen(const views::View* src, gfx::Rect* r) { |
| 21 DCHECK(src); | 22 DCHECK(src); |
| 22 | 23 |
| 23 gfx::Point new_origin = r->origin(); | 24 gfx::Point new_origin = r->origin(); |
| 24 views::View::ConvertPointToScreen(src, &new_origin); | 25 views::View::ConvertPointToScreen(src, &new_origin); |
| 25 r->set_origin(new_origin); | 26 r->set_origin(new_origin); |
| 26 } | 27 } |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 PrefixSelector::PrefixSelector(PrefixDelegate* delegate) | 31 PrefixSelector::PrefixSelector(PrefixDelegate* delegate, View* host_view) |
| 31 : prefix_delegate_(delegate) { | 32 : prefix_delegate_(delegate), host_view_(host_view) { |
| 32 } | 33 } |
| 33 | 34 |
| 34 PrefixSelector::~PrefixSelector() { | 35 PrefixSelector::~PrefixSelector() { |
| 35 } | 36 } |
| 36 | 37 |
| 37 void PrefixSelector::OnViewBlur() { | 38 void PrefixSelector::OnViewBlur() { |
| 38 ClearText(); | 39 ClearText(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void PrefixSelector::SetCompositionText( | 42 void PrefixSelector::SetCompositionText( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 70 | 71 |
| 71 int PrefixSelector::GetTextInputFlags() const { | 72 int PrefixSelector::GetTextInputFlags() const { |
| 72 return 0; | 73 return 0; |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool PrefixSelector::CanComposeInline() const { | 76 bool PrefixSelector::CanComposeInline() const { |
| 76 return false; | 77 return false; |
| 77 } | 78 } |
| 78 | 79 |
| 79 gfx::Rect PrefixSelector::GetCaretBounds() const { | 80 gfx::Rect PrefixSelector::GetCaretBounds() const { |
| 80 gfx::Rect rect(prefix_delegate_->GetVisibleBounds().origin(), gfx::Size()); | 81 gfx::Rect rect(host_view_->GetVisibleBounds().origin(), gfx::Size()); |
| 81 // TextInputClient::GetCaretBounds is expected to return a value in screen | 82 // TextInputClient::GetCaretBounds is expected to return a value in screen |
| 82 // coordinates. | 83 // coordinates. |
| 83 ConvertRectToScreen(prefix_delegate_, &rect); | 84 ConvertRectToScreen(host_view_, &rect); |
| 84 return rect; | 85 return rect; |
| 85 } | 86 } |
| 86 | 87 |
| 87 bool PrefixSelector::GetCompositionCharacterBounds(uint32_t index, | 88 bool PrefixSelector::GetCompositionCharacterBounds(uint32_t index, |
| 88 gfx::Rect* rect) const { | 89 gfx::Rect* rect) const { |
| 89 // TextInputClient::GetCompositionCharacterBounds is expected to fill |rect| | 90 // TextInputClient::GetCompositionCharacterBounds is expected to fill |rect| |
| 90 // in screen coordinates and GetCaretBounds returns screen coordinates. | 91 // in screen coordinates and GetCaretBounds returns screen coordinates. |
| 91 *rect = GetCaretBounds(); | 92 *rect = GetCaretBounds(); |
| 92 return false; | 93 return false; |
| 93 } | 94 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 return (model_text.size() >= lower_text.size()) && | 193 return (model_text.size() >= lower_text.size()) && |
| 193 (model_text.compare(0, lower_text.size(), lower_text) == 0); | 194 (model_text.compare(0, lower_text.size(), lower_text) == 0); |
| 194 } | 195 } |
| 195 | 196 |
| 196 void PrefixSelector::ClearText() { | 197 void PrefixSelector::ClearText() { |
| 197 current_text_.clear(); | 198 current_text_.clear(); |
| 198 time_of_last_key_ = base::TimeTicks(); | 199 time_of_last_key_ = base::TimeTicks(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 } // namespace views | 202 } // namespace views |
| OLD | NEW |