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