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 #ifndef UI_VIEWS_CONTROLS_PREFIX_SELECTOR_H_ | 5 #ifndef UI_VIEWS_CONTROLS_PREFIX_SELECTOR_H_ |
6 #define UI_VIEWS_CONTROLS_PREFIX_SELECTOR_H_ | 6 #define UI_VIEWS_CONTROLS_PREFIX_SELECTOR_H_ |
7 | 7 |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "ui/base/ime/text_input_client.h" | 10 #include "ui/base/ime/text_input_client.h" |
11 #include "ui/views/views_export.h" | 11 #include "ui/views/views_export.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 | 14 |
15 class PrefixDelegate; | 15 class PrefixDelegate; |
16 | 16 |
17 // PrefixSelector is used to change the selection in a view as the user | 17 // PrefixSelector is used to change the selection in a view as the user |
18 // types characters. | 18 // types characters. |
19 class VIEWS_EXPORT PrefixSelector : public ui::TextInputClient { | 19 class VIEWS_EXPORT PrefixSelector : public ui::TextInputClient { |
20 public: | 20 public: |
21 explicit PrefixSelector(PrefixDelegate* delegate); | 21 explicit PrefixSelector(PrefixDelegate* delegate); |
22 virtual ~PrefixSelector(); | 22 ~PrefixSelector() override; |
23 | 23 |
24 // Invoked from the view when it loses focus. | 24 // Invoked from the view when it loses focus. |
25 void OnViewBlur(); | 25 void OnViewBlur(); |
26 | 26 |
27 // ui::TextInputClient: | 27 // ui::TextInputClient: |
28 virtual void SetCompositionText( | 28 void SetCompositionText(const ui::CompositionText& composition) override; |
29 const ui::CompositionText& composition) override; | 29 void ConfirmCompositionText() override; |
30 virtual void ConfirmCompositionText() override; | 30 void ClearCompositionText() override; |
31 virtual void ClearCompositionText() override; | 31 void InsertText(const base::string16& text) override; |
32 virtual void InsertText(const base::string16& text) override; | 32 void InsertChar(base::char16 ch, int flags) override; |
33 virtual void InsertChar(base::char16 ch, int flags) override; | 33 gfx::NativeWindow GetAttachedWindow() const override; |
34 virtual gfx::NativeWindow GetAttachedWindow() const override; | 34 ui::TextInputType GetTextInputType() const override; |
35 virtual ui::TextInputType GetTextInputType() const override; | 35 ui::TextInputMode GetTextInputMode() const override; |
36 virtual ui::TextInputMode GetTextInputMode() const override; | 36 int GetTextInputFlags() const override; |
37 virtual int GetTextInputFlags() const override; | 37 bool CanComposeInline() const override; |
38 virtual bool CanComposeInline() const override; | 38 gfx::Rect GetCaretBounds() const override; |
39 virtual gfx::Rect GetCaretBounds() const override; | 39 bool GetCompositionCharacterBounds(uint32 index, |
40 virtual bool GetCompositionCharacterBounds(uint32 index, | 40 gfx::Rect* rect) const override; |
41 gfx::Rect* rect) const override; | 41 bool HasCompositionText() const override; |
42 virtual bool HasCompositionText() const override; | 42 bool GetTextRange(gfx::Range* range) const override; |
43 virtual bool GetTextRange(gfx::Range* range) const override; | 43 bool GetCompositionTextRange(gfx::Range* range) const override; |
44 virtual bool GetCompositionTextRange(gfx::Range* range) const override; | 44 bool GetSelectionRange(gfx::Range* range) const override; |
45 virtual bool GetSelectionRange(gfx::Range* range) const override; | 45 bool SetSelectionRange(const gfx::Range& range) override; |
46 virtual bool SetSelectionRange(const gfx::Range& range) override; | 46 bool DeleteRange(const gfx::Range& range) override; |
47 virtual bool DeleteRange(const gfx::Range& range) override; | 47 bool GetTextFromRange(const gfx::Range& range, |
48 virtual bool GetTextFromRange(const gfx::Range& range, | 48 base::string16* text) const override; |
49 base::string16* text) const override; | 49 void OnInputMethodChanged() override; |
50 virtual void OnInputMethodChanged() override; | 50 bool ChangeTextDirectionAndLayoutAlignment( |
51 virtual bool ChangeTextDirectionAndLayoutAlignment( | |
52 base::i18n::TextDirection direction) override; | 51 base::i18n::TextDirection direction) override; |
53 virtual void ExtendSelectionAndDelete(size_t before, size_t after) override; | 52 void ExtendSelectionAndDelete(size_t before, size_t after) override; |
54 virtual void EnsureCaretInRect(const gfx::Rect& rect) override; | 53 void EnsureCaretInRect(const gfx::Rect& rect) override; |
55 virtual void OnCandidateWindowShown() override; | 54 void OnCandidateWindowShown() override; |
56 virtual void OnCandidateWindowUpdated() override; | 55 void OnCandidateWindowUpdated() override; |
57 virtual void OnCandidateWindowHidden() override; | 56 void OnCandidateWindowHidden() override; |
58 | 57 |
59 virtual bool IsEditingCommandEnabled(int command_id) override; | 58 bool IsEditingCommandEnabled(int command_id) override; |
60 virtual void ExecuteEditingCommand(int command_id) override; | 59 void ExecuteEditingCommand(int command_id) override; |
61 | 60 |
62 private: | 61 private: |
63 // Invoked when text is typed. Tries to change the selection appropriately. | 62 // Invoked when text is typed. Tries to change the selection appropriately. |
64 void OnTextInput(const base::string16& text); | 63 void OnTextInput(const base::string16& text); |
65 | 64 |
66 // Returns true if the text of the node at |row| starts with |lower_text|. | 65 // Returns true if the text of the node at |row| starts with |lower_text|. |
67 bool TextAtRowMatchesText(int row, const base::string16& lower_text); | 66 bool TextAtRowMatchesText(int row, const base::string16& lower_text); |
68 | 67 |
69 // Clears |current_text_| and resets |time_of_last_key_|. | 68 // Clears |current_text_| and resets |time_of_last_key_|. |
70 void ClearText(); | 69 void ClearText(); |
71 | 70 |
72 PrefixDelegate* prefix_delegate_; | 71 PrefixDelegate* prefix_delegate_; |
73 | 72 |
74 // Time OnTextInput() was last invoked. | 73 // Time OnTextInput() was last invoked. |
75 base::TimeTicks time_of_last_key_; | 74 base::TimeTicks time_of_last_key_; |
76 | 75 |
77 base::string16 current_text_; | 76 base::string16 current_text_; |
78 | 77 |
79 DISALLOW_COPY_AND_ASSIGN(PrefixSelector); | 78 DISALLOW_COPY_AND_ASSIGN(PrefixSelector); |
80 }; | 79 }; |
81 | 80 |
82 } // namespace views | 81 } // namespace views |
83 | 82 |
84 #endif // UI_VIEWS_CONTROLS_PREFIX_SELECTOR_H_ | 83 #endif // UI_VIEWS_CONTROLS_PREFIX_SELECTOR_H_ |
OLD | NEW |