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