OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "chrome/browser/ui/views/dropdown_bar_view.h" | 11 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
12 #include "ui/views/controls/button/button.h" | 12 #include "ui/views/controls/button/button.h" |
13 #include "ui/views/controls/textfield/textfield.h" | 13 #include "ui/views/controls/textfield/textfield.h" |
14 #include "ui/views/controls/textfield/textfield_controller.h" | 14 #include "ui/views/controls/textfield/textfield_controller.h" |
| 15 #include "ui/views/view_targeter_delegate.h" |
15 | 16 |
16 class FindBarHost; | 17 class FindBarHost; |
17 class FindNotificationDetails; | 18 class FindNotificationDetails; |
18 | 19 |
19 namespace views { | 20 namespace views { |
20 class ImageButton; | 21 class ImageButton; |
21 class Label; | 22 class Label; |
22 class MouseEvent; | 23 class MouseEvent; |
23 class Painter; | 24 class Painter; |
24 } | 25 } |
25 | 26 |
26 //////////////////////////////////////////////////////////////////////////////// | 27 //////////////////////////////////////////////////////////////////////////////// |
27 // | 28 // |
28 // The FindBarView is responsible for drawing the UI controls of the | 29 // The FindBarView is responsible for drawing the UI controls of the |
29 // FindBar, the find text box, the 'Find' button and the 'Close' | 30 // FindBar, the find text box, the 'Find' button and the 'Close' |
30 // button. It communicates the user search words to the FindBarHost. | 31 // button. It communicates the user search words to the FindBarHost. |
31 // | 32 // |
32 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
33 class FindBarView : public DropdownBarView, | 34 class FindBarView : public DropdownBarView, |
34 public views::ButtonListener, | 35 public views::ButtonListener, |
35 public views::TextfieldController { | 36 public views::TextfieldController, |
| 37 public views::ViewTargeterDelegate { |
36 public: | 38 public: |
37 // A tag denoting which button the user pressed. | 39 // A tag denoting which button the user pressed. |
38 enum ButtonTag { | 40 enum ButtonTag { |
39 FIND_PREVIOUS_TAG = 0, // The Find Previous button. | 41 FIND_PREVIOUS_TAG = 0, // The Find Previous button. |
40 FIND_NEXT_TAG, // The Find Next button. | 42 FIND_NEXT_TAG, // The Find Next button. |
41 CLOSE_TAG, // The Close button (the 'X'). | 43 CLOSE_TAG, // The Close button (the 'X'). |
42 }; | 44 }; |
43 | 45 |
44 explicit FindBarView(FindBarHost* host); | 46 explicit FindBarView(FindBarHost* host); |
45 ~FindBarView() override; | 47 ~FindBarView() override; |
(...skipping 16 matching lines...) Expand all Loading... |
62 const base::string16& find_text); | 64 const base::string16& find_text); |
63 | 65 |
64 // Clears the current Match Count value in the Find text box. | 66 // Clears the current Match Count value in the Find text box. |
65 void ClearMatchCount(); | 67 void ClearMatchCount(); |
66 | 68 |
67 // Claims focus for the text field and selects its contents. | 69 // Claims focus for the text field and selects its contents. |
68 void SetFocusAndSelection(bool select_all) override; | 70 void SetFocusAndSelection(bool select_all) override; |
69 | 71 |
70 // DropdownBarView: | 72 // DropdownBarView: |
71 void OnPaint(gfx::Canvas* canvas) override; | 73 void OnPaint(gfx::Canvas* canvas) override; |
| 74 void OnPaintBackground(gfx::Canvas* canvas) override; |
72 void Layout() override; | 75 void Layout() override; |
73 gfx::Size GetPreferredSize() const override; | 76 gfx::Size GetPreferredSize() const override; |
74 | 77 |
75 // views::ButtonListener: | 78 // views::ButtonListener: |
76 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 79 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
77 | 80 |
78 // views::TextfieldController: | 81 // views::TextfieldController: |
79 bool HandleKeyEvent(views::Textfield* sender, | 82 bool HandleKeyEvent(views::Textfield* sender, |
80 const ui::KeyEvent& key_event) override; | 83 const ui::KeyEvent& key_event) override; |
81 void OnAfterUserAction(views::Textfield* sender) override; | 84 void OnAfterUserAction(views::Textfield* sender) override; |
82 void OnAfterPaste() override; | 85 void OnAfterPaste() override; |
83 | 86 |
| 87 // views::ViewTargeterDelegate: |
| 88 views::View* TargetForRect(View* root, const gfx::Rect& rect) override; |
| 89 |
84 private: | 90 private: |
| 91 // Does mode-specific init. The NonMaterial version should eventually be |
| 92 // removed in favor of Material. |
| 93 void InitViewsForNonMaterial(); |
| 94 void InitViewsForMaterial(); |
| 95 |
85 // Starts finding |search_text|. If the text is empty, stops finding. | 96 // Starts finding |search_text|. If the text is empty, stops finding. |
86 void Find(const base::string16& search_text); | 97 void Find(const base::string16& search_text); |
87 | 98 |
88 // Updates the appearance for the match count label. | 99 // Updates the appearance for the match count label. |
89 void UpdateMatchCountAppearance(bool no_match); | 100 void UpdateMatchCountAppearance(bool no_match); |
90 | 101 |
91 // DropdownBarView: | 102 // DropdownBarView: |
92 const char* GetClassName() const override; | 103 const char* GetClassName() const override; |
93 void OnThemeChanged() override; | 104 void OnThemeChanged() override; |
| 105 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
94 | 106 |
95 // We use a hidden view to grab mouse clicks and bring focus to the find | 107 // We use a hidden view to grab mouse clicks and bring focus to the find |
96 // text box. This is because although the find text box may look like it | 108 // text box. This is because although the find text box may look like it |
97 // extends all the way to the find button, it only goes as far as to the | 109 // extends all the way to the find button, it only goes as far as to the |
98 // match_count label. The user, however, expects being able to click anywhere | 110 // match_count label. The user, however, expects being able to click anywhere |
99 // inside what looks like the find text box (including on or around the | 111 // inside what looks like the find text box (including on or around the |
100 // match_count label) and have focus brought to the find box. | 112 // match_count label) and have focus brought to the find box. |
101 class FocusForwarderView : public views::View { | 113 class FocusForwarderView : public views::View { |
102 public: | 114 public: |
103 explicit FocusForwarderView( | 115 explicit FocusForwarderView( |
(...skipping 13 matching lines...) Expand all Loading... |
117 FindBarHost* find_bar_host() const; | 129 FindBarHost* find_bar_host() const; |
118 | 130 |
119 // Used to detect if the input text, not including the IME composition text, | 131 // Used to detect if the input text, not including the IME composition text, |
120 // has changed or not. | 132 // has changed or not. |
121 base::string16 last_searched_text_; | 133 base::string16 last_searched_text_; |
122 | 134 |
123 // The controls in the window. | 135 // The controls in the window. |
124 views::Textfield* find_text_; | 136 views::Textfield* find_text_; |
125 scoped_ptr<views::Painter> find_text_border_; | 137 scoped_ptr<views::Painter> find_text_border_; |
126 views::Label* match_count_text_; | 138 views::Label* match_count_text_; |
127 FocusForwarderView* focus_forwarder_view_; | 139 views::View* focus_forwarder_view_; |
128 views::ImageButton* find_previous_button_; | 140 views::ImageButton* find_previous_button_; |
129 views::ImageButton* find_next_button_; | 141 views::ImageButton* find_next_button_; |
130 views::ImageButton* close_button_; | 142 views::ImageButton* close_button_; |
131 | 143 |
132 // The preferred height of the find bar. | 144 // The preferred height of the find bar. |
133 int preferred_height_; | 145 int preferred_height_; |
134 | 146 |
135 DISALLOW_COPY_AND_ASSIGN(FindBarView); | 147 DISALLOW_COPY_AND_ASSIGN(FindBarView); |
136 }; | 148 }; |
137 | 149 |
138 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ | 150 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ |
OLD | NEW |