Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(619)

Side by Side Diff: chrome/browser/ui/views/omnibox/inline_omnibox_popup_view.h

Issue 10580039: Adds ability to render omnibox as a view above the page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ 5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_INLINE_OMNIBOX_POPUP_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ 6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_INLINE_OMNIBOX_POPUP_VIEW_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/autocomplete/autocomplete.h" 10 #include "chrome/browser/autocomplete/autocomplete.h"
11 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 11 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
12 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" 12 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
13 #include "chrome/browser/ui/views/omnibox/omnibox_result_view_model.h" 13 #include "chrome/browser/ui/views/omnibox/omnibox_result_view_model.h"
14 #include "ui/base/animation/animation_delegate.h" 14 #include "ui/base/animation/animation_delegate.h"
15 #include "ui/base/animation/slide_animation.h" 15 #include "ui/base/animation/slide_animation.h"
16 #include "ui/gfx/font.h" 16 #include "ui/gfx/font.h"
17 #include "ui/views/view.h" 17 #include "ui/views/view.h"
18 #include "webkit/glue/window_open_disposition.h" 18 #include "webkit/glue/window_open_disposition.h"
19 19
20 class AutocompleteEditModel; 20 class AutocompleteEditModel;
21 struct AutocompleteMatch; 21 struct AutocompleteMatch;
22 class OmniboxResultView; 22 class OmniboxResultView;
23 class Profile; 23 class Profile;
24 24
25 namespace views { 25 namespace views {
26 class BubbleBorder; 26 class BubbleBorder;
27 } 27 }
28 28
29 // A view representing the contents of the autocomplete popup. 29 // A view representing the contents of the omnibox popup.
30 class OmniboxPopupContentsView : public views::View, 30 class InlineOmniboxPopupView : public views::View,
31 public OmniboxResultViewModel, 31 public OmniboxResultViewModel,
32 public OmniboxPopupView, 32 public OmniboxPopupView,
33 public ui::AnimationDelegate { 33 public ui::AnimationDelegate {
34 public: 34 public:
35 // Creates the appropriate type of omnibox dropdown for the 35 InlineOmniboxPopupView(const gfx::Font& font,
36 // current environment, e.g. desktop vs. touch optimized layout. 36 OmniboxView* omnibox_view,
37 static OmniboxPopupContentsView* CreateForEnvironment( 37 AutocompleteEditModel* edit_model,
38 const gfx::Font& font, 38 views::View* location_bar);
39 OmniboxView* omnibox_view, 39
40 AutocompleteEditModel* edit_model, 40 // Call immediately after construction.
41 views::View* location_bar); 41 void Init();
42 42
43 // Returns the bounds the popup should be shown at. This is the display bounds 43 // Returns the bounds the popup should be shown at. This is the display bounds
44 // and includes offsets for the dropshadow which this view's border renders. 44 // and includes offsets for the dropshadow which this view's border renders.
45 gfx::Rect GetPopupBounds() const; 45 gfx::Rect GetPopupBounds() const;
46 46
47 virtual void LayoutChildren(); 47 virtual void LayoutChildren();
48 48
49 // Overridden from OmniboxPopupView: 49 // Overridden from AutocompletePopupView:
Peter Kasting 2012/06/22 20:33:22 Nit: You branched off before tfarina renamed a bun
50 virtual bool IsOpen() const OVERRIDE; 50 virtual bool IsOpen() const OVERRIDE;
51 virtual void InvalidateLine(size_t line) OVERRIDE; 51 virtual void InvalidateLine(size_t line) OVERRIDE;
52 virtual void UpdatePopupAppearance() OVERRIDE; 52 virtual void UpdatePopupAppearance() OVERRIDE;
53 virtual gfx::Rect GetTargetBounds() OVERRIDE; 53 virtual gfx::Rect GetTargetBounds() OVERRIDE;
54 virtual void PaintUpdatesNow() OVERRIDE; 54 virtual void PaintUpdatesNow() OVERRIDE;
55 virtual void OnDragCanceled() OVERRIDE; 55 virtual void OnDragCanceled() OVERRIDE;
56 56
57 // Overridden from OmniboxResultViewModel: 57 // Overridden from OmniboxResultViewModel:
58 virtual bool IsSelectedIndex(size_t index) const OVERRIDE; 58 virtual bool IsSelectedIndex(size_t index) const OVERRIDE;
59 virtual bool IsHoveredIndex(size_t index) const OVERRIDE; 59 virtual bool IsHoveredIndex(size_t index) const OVERRIDE;
60 virtual const SkBitmap* GetIconIfExtensionMatch(size_t index) const OVERRIDE; 60 virtual const SkBitmap* GetIconIfExtensionMatch(size_t index) const OVERRIDE;
61 61
62 // Overridden from ui::AnimationDelegate: 62 // Overridden from ui::AnimationDelegate:
63 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 63 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
64 64
65 // Overridden from views::View: 65 // Overridden from views::View:
66 virtual gfx::Size GetPreferredSize() OVERRIDE;
66 virtual void Layout() OVERRIDE; 67 virtual void Layout() OVERRIDE;
67 virtual views::View* GetEventHandlerForPoint( 68 virtual views::View* GetEventHandlerForPoint(
68 const gfx::Point& point) OVERRIDE; 69 const gfx::Point& point) OVERRIDE;
69 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; 70 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
70 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; 71 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
71 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; 72 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
72 virtual void OnMouseCaptureLost() OVERRIDE; 73 virtual void OnMouseCaptureLost() OVERRIDE;
73 virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; 74 virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE;
74 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; 75 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE;
75 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; 76 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
76 virtual ui::GestureStatus OnGestureEvent( 77 virtual ui::GestureStatus OnGestureEvent(
77 const views::GestureEvent& event) OVERRIDE; 78 const views::GestureEvent& event) OVERRIDE;
78 79
79 protected: 80 protected:
80 OmniboxPopupContentsView(const gfx::Font& font, 81 virtual ~InlineOmniboxPopupView();
81 OmniboxView* omnibox_view,
82 AutocompleteEditModel* edit_model,
83 views::View* location_bar);
84 virtual ~OmniboxPopupContentsView();
85
86 virtual void PaintResultViews(gfx::Canvas* canvas);
87 82
88 // Calculates the height needed to show all the results in the model. 83 // Calculates the height needed to show all the results in the model.
89 virtual int CalculatePopupHeight(); 84 virtual int CalculatePopupHeight();
90 virtual OmniboxResultView* CreateResultView( 85 virtual OmniboxResultView* CreateResultView(
91 OmniboxResultViewModel* model, 86 OmniboxResultViewModel* model,
92 int model_index, 87 int model_index,
93 const gfx::Font& font, 88 const gfx::Font& font,
94 const gfx::Font& bold_font); 89 const gfx::Font& bold_font);
95 90
96 // Overridden from views::View:
97 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
98 // This method should not be triggered directly as we paint our children
99 // in an un-conventional way inside OnPaint. We use a separate canvas to
100 // paint the children. Hence we override this method to a no-op so that
101 // the view hierarchy does not "accidentally" trigger this.
102 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
103
104 scoped_ptr<OmniboxPopupModel> model_; 91 scoped_ptr<OmniboxPopupModel> model_;
105 92
106 private: 93 private:
107 class AutocompletePopupWidget; 94 class AutocompletePopupWidget;
108 95
109 // Call immediately after construction.
110 void Init();
111
112 // Returns true if the model has a match at the specified index. 96 // Returns true if the model has a match at the specified index.
113 bool HasMatchAt(size_t index) const; 97 bool HasMatchAt(size_t index) const;
114 98
115 // Returns the match at the specified index within the popup model. 99 // Returns the match at the specified index within the popup model.
116 const AutocompleteMatch& GetMatchAtIndex(size_t index) const; 100 const AutocompleteMatch& GetMatchAtIndex(size_t index) const;
117 101
118 // Fill a path for the contents' roundrect. |bounding_rect| is the rect that 102 // Fill a path for the contents' roundrect. |bounding_rect| is the rect that
119 // bounds the path. 103 // bounds the path.
120 void MakeContentsPath(gfx::Path* path, const gfx::Rect& bounding_rect); 104 void MakeContentsPath(gfx::Path* path, const gfx::Rect& bounding_rect);
121 105
122 // Updates the window's blur region for the current size.
123 void UpdateBlurRegion();
124
125 // Makes the contents of the canvas slightly transparent.
126 void MakeCanvasTransparent(gfx::Canvas* canvas);
127
128 // Called when the line at the specified index should be opened with the 106 // Called when the line at the specified index should be opened with the
129 // provided disposition. 107 // provided disposition.
130 void OpenIndex(size_t index, WindowOpenDisposition disposition); 108 void OpenIndex(size_t index, WindowOpenDisposition disposition);
131 109
132 // Find the index of the match under the given |point|, specified in window 110 // Find the index of the match under the given |point|, specified in window
133 // coordinates. Returns OmniboxPopupModel::kNoMatch if there isn't a match at 111 // coordinates. Returns AutocompletePopupModel::kNoMatch if there isn't a
134 // the specified point. 112 // match at the specified point.
135 size_t GetIndexForPoint(const gfx::Point& point); 113 size_t GetIndexForPoint(const gfx::Point& point);
136 114
137 // Processes a located event (e.g. mouse/gesture) and sets the selection/hover 115 // Processes a located event (e.g. mouse/gesture) and sets the selection/hover
138 // state of a line in the list. 116 // state of a line in the list.
139 void UpdateLineEvent(const views::LocatedEvent& event, 117 void UpdateLineEvent(const views::LocatedEvent& event,
140 bool should_set_selected_line); 118 bool should_set_selected_line);
141 119
142 // Opens an entry from the list depending on the event and the selected 120 // Opens an entry from the list depending on the event and the selected
143 // disposition. 121 // disposition.
144 void OpenSelectedLine(const views::LocatedEvent& event, 122 void OpenSelectedLine(const views::LocatedEvent& event,
145 WindowOpenDisposition disposition); 123 WindowOpenDisposition disposition);
146 124
147 // Returns the target bounds given the specified content height. 125 // Returns the target bounds given the specified content height.
126 // TODO(sky): convert to size.
148 gfx::Rect CalculateTargetBounds(int h); 127 gfx::Rect CalculateTargetBounds(int h);
149 128
150 // The popup that contains this view. We create this, but it deletes itself
151 // when its window is destroyed. This is a WeakPtr because it's possible for
152 // the OS to destroy the window and thus delete this object before we're
153 // deleted, or without our knowledge.
154 base::WeakPtr<AutocompletePopupWidget> popup_;
155
156 // The edit view that invokes us. 129 // The edit view that invokes us.
157 OmniboxView* omnibox_view_; 130 OmniboxView* omnibox_view_;
158 131
159 Profile* profile_; 132 Profile* profile_;
160 133
161 // An object that the popup positions itself against. 134 // An object that the popup positions itself against.
162 views::View* location_bar_; 135 views::View* location_bar_;
163 136
164 // Our border, which can compute our desired bounds.
165 const views::BubbleBorder* bubble_border_;
166
167 // The font that we should use for result rows. This is based on the font used 137 // The font that we should use for result rows. This is based on the font used
168 // by the edit that created us. 138 // by the edit that created us.
169 gfx::Font result_font_; 139 gfx::Font result_font_;
170 140
171 // The font used for portions that match the input. 141 // The font used for portions that match the input.
172 gfx::Font result_bold_font_; 142 gfx::Font result_bold_font_;
173 143
174 // If the user cancels a dragging action (i.e. by pressing ESC), we don't have 144 // If the user cancels a dragging action (i.e. by pressing ESC), we don't have
175 // a convenient way to release mouse capture. Instead we use this flag to 145 // a convenient way to release mouse capture. Instead we use this flag to
176 // simply ignore all remaining drag events, and the eventual mouse release 146 // simply ignore all remaining drag events, and the eventual mouse release
177 // event. Since OnDragCanceled() can be called when we're not dragging, this 147 // event. Since OnDragCanceled() can be called when we're not dragging, this
178 // flag is reset to false on a mouse pressed event, to make sure we don't 148 // flag is reset to false on a mouse pressed event, to make sure we don't
179 // erroneously ignore the next drag. 149 // erroneously ignore the next drag.
180 bool ignore_mouse_drag_; 150 bool ignore_mouse_drag_;
181 151
182 // The popup sizes vertically using an animation when the popup is getting 152 // The popup sizes vertically using an animation when the popup is getting
183 // shorter (not larger, that makes it look "slow"). 153 // shorter (not larger, that makes it look "slow").
184 ui::SlideAnimation size_animation_; 154 ui::SlideAnimation size_animation_;
155 // TODO(sky): convert to sizes.
185 gfx::Rect start_bounds_; 156 gfx::Rect start_bounds_;
186 gfx::Rect target_bounds_; 157 gfx::Rect target_bounds_;
187 158
188 DISALLOW_COPY_AND_ASSIGN(OmniboxPopupContentsView); 159 DISALLOW_COPY_AND_ASSIGN(InlineOmniboxPopupView);
189 }; 160 };
190 161
191 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_POPUP_CONTENTS_VIEW_H_ 162 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_INLINE_OMNIBOX_POPUP_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698