BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / views / find_bar_view.h
blob5fac1d1955d17a8777b4600d811d897d6cd75999
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h"
11 #include "chrome/browser/ui/views/dropdown_bar_view.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/textfield/textfield.h"
14 #include "ui/views/controls/textfield/textfield_controller.h"
15 #include "ui/views/view_targeter_delegate.h"
17 class FindBarHost;
18 class FindNotificationDetails;
20 namespace views {
21 class ImageButton;
22 class Label;
23 class MouseEvent;
24 class Painter;
27 ////////////////////////////////////////////////////////////////////////////////
29 // The FindBarView is responsible for drawing the UI controls of the
30 // FindBar, the find text box, the 'Find' button and the 'Close'
31 // button. It communicates the user search words to the FindBarHost.
33 ////////////////////////////////////////////////////////////////////////////////
34 class FindBarView : public DropdownBarView,
35 public views::ButtonListener,
36 public views::TextfieldController,
37 public views::ViewTargeterDelegate {
38 public:
39 // A tag denoting which button the user pressed.
40 enum ButtonTag {
41 FIND_PREVIOUS_TAG = 0, // The Find Previous button.
42 FIND_NEXT_TAG, // The Find Next button.
43 CLOSE_TAG, // The Close button (the 'X').
46 explicit FindBarView(FindBarHost* host);
47 ~FindBarView() override;
49 // Accessors for the text and selection displayed in the text box.
50 void SetFindTextAndSelectedRange(const base::string16& find_text,
51 const gfx::Range& selected_range);
52 base::string16 GetFindText() const;
53 gfx::Range GetSelectedRange() const;
55 // Gets the selected text in the text box.
56 base::string16 GetFindSelectedText() const;
58 // Gets the match count text displayed in the text box.
59 base::string16 GetMatchCountText() const;
61 // Updates the label inside the Find text box that shows the ordinal of the
62 // active item and how many matches were found.
63 void UpdateForResult(const FindNotificationDetails& result,
64 const base::string16& find_text);
66 // Clears the current Match Count value in the Find text box.
67 void ClearMatchCount();
69 // Claims focus for the text field and selects its contents.
70 void SetFocusAndSelection(bool select_all) override;
72 // DropdownBarView:
73 void OnPaint(gfx::Canvas* canvas) override;
74 void OnPaintBackground(gfx::Canvas* canvas) override;
75 void Layout() override;
76 gfx::Size GetPreferredSize() const override;
78 // views::ButtonListener:
79 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
81 // views::TextfieldController:
82 bool HandleKeyEvent(views::Textfield* sender,
83 const ui::KeyEvent& key_event) override;
84 void OnAfterUserAction(views::Textfield* sender) override;
85 void OnAfterPaste() override;
87 // views::ViewTargeterDelegate:
88 views::View* TargetForRect(View* root, const gfx::Rect& rect) override;
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();
96 // Starts finding |search_text|. If the text is empty, stops finding.
97 void Find(const base::string16& search_text);
99 // Updates the appearance for the match count label.
100 void UpdateMatchCountAppearance(bool no_match);
102 // DropdownBarView:
103 const char* GetClassName() const override;
104 void OnThemeChanged() override;
105 void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
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) {}
119 private:
120 bool OnMousePressed(const ui::MouseEvent& event) override;
122 views::Textfield* view_to_focus_on_mousedown_;
124 DISALLOW_COPY_AND_ASSIGN(FocusForwarderView);
127 // Returns the OS-specific view for the find bar that acts as an intermediary
128 // between us and the WebContentsView.
129 FindBarHost* find_bar_host() const;
131 // Used to detect if the input text, not including the IME composition text,
132 // has changed or not.
133 base::string16 last_searched_text_;
135 // The controls in the window.
136 views::Textfield* find_text_;
137 scoped_ptr<views::Painter> find_text_border_;
138 views::Label* match_count_text_;
139 views::View* focus_forwarder_view_;
140 views::ImageButton* find_previous_button_;
141 views::ImageButton* find_next_button_;
142 views::ImageButton* close_button_;
144 // The preferred height of the find bar.
145 int preferred_height_;
147 DISALLOW_COPY_AND_ASSIGN(FindBarView);
150 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_VIEW_H_