| 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/button/vector_icon_image_button_observer.h" |
| 15 #include "ui/views/controls/textfield/textfield_controller.h" | 16 #include "ui/views/controls/textfield/textfield_controller.h" |
| 16 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
| 17 #include "ui/views/view_targeter_delegate.h" | 18 #include "ui/views/view_targeter_delegate.h" |
| 18 | 19 |
| 19 class FindBarHost; | 20 class FindBarHost; |
| 20 class FindNotificationDetails; | 21 class FindNotificationDetails; |
| 21 | 22 |
| 22 namespace gfx { | 23 namespace gfx { |
| 23 class Range; | 24 class Range; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace views { | 27 namespace views { |
| 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 class ImageButton; |
| 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 views::View, | 42 class FindBarView : public views::View, |
| 42 public DropdownBarHostDelegate, | 43 public DropdownBarHostDelegate, |
| 43 public views::VectorIconButtonDelegate, | 44 public views::ButtonListener, |
| 44 public views::TextfieldController, | 45 public views::TextfieldController, |
| 45 public views::ViewTargeterDelegate { | 46 public views::ViewTargeterDelegate { |
| 46 public: | 47 public: |
| 47 explicit FindBarView(FindBarHost* host); | 48 explicit FindBarView(FindBarHost* host); |
| 48 ~FindBarView() override; | 49 ~FindBarView() override; |
| 49 | 50 |
| 50 // Accessors for the text and selection displayed in the text box. | 51 // Accessors for the text and selection displayed in the text box. |
| 51 void SetFindTextAndSelectedRange(const base::string16& find_text, | 52 void SetFindTextAndSelectedRange(const base::string16& find_text, |
| 52 const gfx::Range& selected_range); | 53 const gfx::Range& selected_range); |
| 53 base::string16 GetFindText() const; | 54 base::string16 GetFindText() const; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 67 // Clears the current Match Count value in the Find text box. | 68 // Clears the current Match Count value in the Find text box. |
| 68 void ClearMatchCount(); | 69 void ClearMatchCount(); |
| 69 | 70 |
| 70 // views::View: | 71 // views::View: |
| 71 void Layout() override; | 72 void Layout() override; |
| 72 gfx::Size GetPreferredSize() const override; | 73 gfx::Size GetPreferredSize() const override; |
| 73 | 74 |
| 74 // DropdownBarHostDelegate: | 75 // DropdownBarHostDelegate: |
| 75 void SetFocusAndSelection(bool select_all) override; | 76 void SetFocusAndSelection(bool select_all) override; |
| 76 | 77 |
| 77 // views::VectorIconButtonDelegate: | 78 // views::ButtonListener: |
| 78 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 79 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 79 SkColor GetVectorIconBaseColor() const override; | |
| 80 | 80 |
| 81 // views::TextfieldController: | 81 // views::TextfieldController: |
| 82 bool HandleKeyEvent(views::Textfield* sender, | 82 bool HandleKeyEvent(views::Textfield* sender, |
| 83 const ui::KeyEvent& key_event) override; | 83 const ui::KeyEvent& key_event) override; |
| 84 void OnAfterUserAction(views::Textfield* sender) override; | 84 void OnAfterUserAction(views::Textfield* sender) override; |
| 85 void OnAfterPaste() override; | 85 void OnAfterPaste() override; |
| 86 | 86 |
| 87 // views::ViewTargeterDelegate: | 87 // views::ViewTargeterDelegate: |
| 88 views::View* TargetForRect(View* root, const gfx::Rect& rect) override; | 88 views::View* TargetForRect(View* root, const gfx::Rect& rect) override; |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 class FindBarViewButtonObserver |
| 92 : public views::VectorIconImageButtonObserver { |
| 93 public: |
| 94 explicit FindBarViewButtonObserver(FindBarView* parent); |
| 95 |
| 96 private: |
| 97 // views::VectorIconImageButtonObserver: |
| 98 const gfx::VectorIcon& GetVectorIcon(View* view) const override; |
| 99 SkColor GetVectorIconColor() const override; |
| 100 |
| 101 FindBarView* parent_; |
| 102 }; |
| 103 |
| 104 views::ImageButton* CreateButton(const gfx::VectorIcon& icon); |
| 105 |
| 91 // Starts finding |search_text|. If the text is empty, stops finding. | 106 // Starts finding |search_text|. If the text is empty, stops finding. |
| 92 void Find(const base::string16& search_text); | 107 void Find(const base::string16& search_text); |
| 93 | 108 |
| 94 // Updates the appearance for the match count label. | 109 // Updates the appearance for the match count label. |
| 95 void UpdateMatchCountAppearance(bool no_match); | 110 void UpdateMatchCountAppearance(bool no_match); |
| 96 | 111 |
| 97 // DropdownBarView: | 112 // DropdownBarView: |
| 98 const char* GetClassName() const override; | 113 const char* GetClassName() const override; |
| 99 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; | 114 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 100 | 115 |
| 101 // Returns the color for the icons on the buttons per the current NativeTheme. | 116 // Returns the color for the icons on the buttons per the current NativeTheme. |
| 102 SkColor GetTextColorForIcon(); | 117 SkColor GetTextColorForIcon(); |
| 103 | 118 |
| 104 // The OS-specific view for the find bar that acts as an intermediary | 119 // The OS-specific view for the find bar that acts as an intermediary |
| 105 // between us and the WebContentsView. | 120 // between us and the WebContentsView. |
| 106 FindBarHost* find_bar_host_; | 121 FindBarHost* find_bar_host_; |
| 107 | 122 |
| 108 // Used to detect if the input text, not including the IME composition text, | 123 // Used to detect if the input text, not including the IME composition text, |
| 109 // has changed or not. | 124 // has changed or not. |
| 110 base::string16 last_searched_text_; | 125 base::string16 last_searched_text_; |
| 111 | 126 |
| 112 // The controls in the window. | 127 // The controls in the window. |
| 113 views::Textfield* find_text_; | 128 views::Textfield* find_text_; |
| 114 std::unique_ptr<views::Painter> find_text_border_; | 129 std::unique_ptr<views::Painter> find_text_border_; |
| 115 views::Label* match_count_text_; | 130 views::Label* match_count_text_; |
| 116 views::View* focus_forwarder_view_; | 131 views::View* focus_forwarder_view_; |
| 117 views::Separator* separator_; | 132 views::Separator* separator_; |
| 118 views::VectorIconButton* find_previous_button_; | 133 FindBarViewButtonObserver button_observer_; |
| 119 views::VectorIconButton* find_next_button_; | 134 views::ImageButton* find_previous_button_; |
| 120 views::VectorIconButton* close_button_; | 135 views::ImageButton* find_next_button_; |
| 136 views::ImageButton* close_button_; |
| 121 | 137 |
| 122 // The preferred height of the find bar. | 138 // The preferred height of the find bar. |
| 123 int preferred_height_; | 139 int preferred_height_; |
| 124 | 140 |
| 125 DISALLOW_COPY_AND_ASSIGN(FindBarView); | 141 DISALLOW_COPY_AND_ASSIGN(FindBarView); |
| 126 }; | 142 }; |
| 127 | 143 |
| 128 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ | 144 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_ |
| OLD | NEW |