| 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_host_delegate.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_controller.h" | 15 #include "ui/views/controls/textfield/textfield_controller.h" |
| 16 #include "ui/views/view.h" |
| 16 #include "ui/views/view_targeter_delegate.h" | 17 #include "ui/views/view_targeter_delegate.h" |
| 17 | 18 |
| 18 class FindBarHost; | 19 class FindBarHost; |
| 19 class FindNotificationDetails; | 20 class FindNotificationDetails; |
| 20 | 21 |
| 21 namespace gfx { | 22 namespace gfx { |
| 22 class Range; | 23 class Range; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace views { | 26 namespace views { |
| 26 class Label; | 27 class Label; |
| 27 class MouseEvent; | 28 class MouseEvent; |
| 28 class Painter; | 29 class Painter; |
| 29 class Separator; | 30 class Separator; |
| 30 class Textfield; | 31 class Textfield; |
| 31 class VectorIconButton; | 32 class VectorIconButton; |
| 32 } | 33 } |
| 33 | 34 |
| 34 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
| 35 // | 36 // |
| 36 // The FindBarView is responsible for drawing the UI controls of the | 37 // The FindBarView is responsible for drawing the UI controls of the |
| 37 // FindBar, the find text box, the 'Find' button and the 'Close' | 38 // FindBar, the find text box, the 'Find' button and the 'Close' |
| 38 // button. It communicates the user search words to the FindBarHost. | 39 // button. It communicates the user search words to the FindBarHost. |
| 39 // | 40 // |
| 40 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
| 41 class FindBarView : public DropdownBarView, | 42 class FindBarView : public views::View, |
| 43 public DropdownBarHostDelegate, |
| 42 public views::VectorIconButtonDelegate, | 44 public views::VectorIconButtonDelegate, |
| 43 public views::TextfieldController, | 45 public views::TextfieldController, |
| 44 public views::ViewTargeterDelegate { | 46 public views::ViewTargeterDelegate { |
| 45 public: | 47 public: |
| 46 explicit FindBarView(FindBarHost* host); | 48 explicit FindBarView(FindBarHost* host); |
| 47 ~FindBarView() override; | 49 ~FindBarView() override; |
| 48 | 50 |
| 49 // Accessors for the text and selection displayed in the text box. | 51 // Accessors for the text and selection displayed in the text box. |
| 50 void SetFindTextAndSelectedRange(const base::string16& find_text, | 52 void SetFindTextAndSelectedRange(const base::string16& find_text, |
| 51 const gfx::Range& selected_range); | 53 const gfx::Range& selected_range); |
| 52 base::string16 GetFindText() const; | 54 base::string16 GetFindText() const; |
| 53 gfx::Range GetSelectedRange() const; | 55 gfx::Range GetSelectedRange() const; |
| 54 | 56 |
| 55 // Gets the selected text in the text box. | 57 // Gets the selected text in the text box. |
| 56 base::string16 GetFindSelectedText() const; | 58 base::string16 GetFindSelectedText() const; |
| 57 | 59 |
| 58 // Gets the match count text displayed in the text box. | 60 // Gets the match count text displayed in the text box. |
| 59 base::string16 GetMatchCountText() const; | 61 base::string16 GetMatchCountText() const; |
| 60 | 62 |
| 61 // Updates the label inside the Find text box that shows the ordinal of the | 63 // Updates the label inside the Find text box that shows the ordinal of the |
| 62 // active item and how many matches were found. | 64 // active item and how many matches were found. |
| 63 void UpdateForResult(const FindNotificationDetails& result, | 65 void UpdateForResult(const FindNotificationDetails& result, |
| 64 const base::string16& find_text); | 66 const base::string16& find_text); |
| 65 | 67 |
| 66 // Clears the current Match Count value in the Find text box. | 68 // Clears the current Match Count value in the Find text box. |
| 67 void ClearMatchCount(); | 69 void ClearMatchCount(); |
| 68 | 70 |
| 69 // Claims focus for the text field and selects its contents. | 71 // views::View: |
| 70 void SetFocusAndSelection(bool select_all) override; | |
| 71 | |
| 72 // DropdownBarView: | |
| 73 void Layout() override; | 72 void Layout() override; |
| 74 gfx::Size GetPreferredSize() const override; | 73 gfx::Size GetPreferredSize() const override; |
| 75 | 74 |
| 75 // DropdownBarHostDelegate: |
| 76 void SetFocusAndSelection(bool select_all) override; |
| 77 |
| 76 // views::VectorIconButtonDelegate: | 78 // views::VectorIconButtonDelegate: |
| 77 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 79 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 78 SkColor GetVectorIconBaseColor() const override; | 80 SkColor GetVectorIconBaseColor() const override; |
| 79 | 81 |
| 80 // views::TextfieldController: | 82 // views::TextfieldController: |
| 81 bool HandleKeyEvent(views::Textfield* sender, | 83 bool HandleKeyEvent(views::Textfield* sender, |
| 82 const ui::KeyEvent& key_event) override; | 84 const ui::KeyEvent& key_event) override; |
| 83 void OnAfterUserAction(views::Textfield* sender) override; | 85 void OnAfterUserAction(views::Textfield* sender) override; |
| 84 void OnAfterPaste() override; | 86 void OnAfterPaste() override; |
| 85 | 87 |
| 86 // views::ViewTargeterDelegate: | 88 // views::ViewTargeterDelegate: |
| 87 views::View* TargetForRect(View* root, const gfx::Rect& rect) override; | 89 views::View* TargetForRect(View* root, const gfx::Rect& rect) override; |
| 88 | 90 |
| 89 private: | 91 private: |
| 90 // Starts finding |search_text|. If the text is empty, stops finding. | 92 // Starts finding |search_text|. If the text is empty, stops finding. |
| 91 void Find(const base::string16& search_text); | 93 void Find(const base::string16& search_text); |
| 92 | 94 |
| 93 // Updates the appearance for the match count label. | 95 // Updates the appearance for the match count label. |
| 94 void UpdateMatchCountAppearance(bool no_match); | 96 void UpdateMatchCountAppearance(bool no_match); |
| 95 | 97 |
| 96 // DropdownBarView: | 98 // DropdownBarView: |
| 97 const char* GetClassName() const override; | 99 const char* GetClassName() const override; |
| 98 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 100 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 99 | 101 |
| 100 // Returns the color for the icons on the buttons per the current NativeTheme. | 102 // Returns the color for the icons on the buttons per the current NativeTheme. |
| 101 SkColor GetTextColorForIcon(); | 103 SkColor GetTextColorForIcon(); |
| 102 | 104 |
| 103 // Returns the OS-specific view for the find bar that acts as an intermediary | 105 // The OS-specific view for the find bar that acts as an intermediary |
| 104 // between us and the WebContentsView. | 106 // between us and the WebContentsView. |
| 105 FindBarHost* find_bar_host() const; | 107 FindBarHost* find_bar_host_; |
| 106 | 108 |
| 107 // Used to detect if the input text, not including the IME composition text, | 109 // Used to detect if the input text, not including the IME composition text, |
| 108 // has changed or not. | 110 // has changed or not. |
| 109 base::string16 last_searched_text_; | 111 base::string16 last_searched_text_; |
| 110 | 112 |
| 111 // The controls in the window. | 113 // The controls in the window. |
| 112 views::Textfield* find_text_; | 114 views::Textfield* find_text_; |
| 113 std::unique_ptr<views::Painter> find_text_border_; | 115 std::unique_ptr<views::Painter> find_text_border_; |
| 114 views::Label* match_count_text_; | 116 views::Label* match_count_text_; |
| 115 views::View* focus_forwarder_view_; | 117 views::View* focus_forwarder_view_; |
| 116 views::Separator* separator_; | 118 views::Separator* separator_; |
| 117 views::VectorIconButton* find_previous_button_; | 119 views::VectorIconButton* find_previous_button_; |
| 118 views::VectorIconButton* find_next_button_; | 120 views::VectorIconButton* find_next_button_; |
| 119 views::VectorIconButton* close_button_; | 121 views::VectorIconButton* close_button_; |
| 120 | 122 |
| 121 // The preferred height of the find bar. | 123 // The preferred height of the find bar. |
| 122 int preferred_height_; | 124 int preferred_height_; |
| 123 | 125 |
| 124 DISALLOW_COPY_AND_ASSIGN(FindBarView); | 126 DISALLOW_COPY_AND_ASSIGN(FindBarView); |
| 125 }; | 127 }; |
| 126 | 128 |
| 127 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ | 129 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ |
| OLD | NEW |