| OLD | NEW | 
|---|
|  | (Empty) | 
| 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. |  | 
| 4 |  | 
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ |  | 
| 6 #define CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW_H_ |  | 
| 7 #pragma once |  | 
| 8 |  | 
| 9 #include "base/memory/weak_ptr.h" |  | 
| 10 #include "chrome/browser/autocomplete/autocomplete.h" |  | 
| 11 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |  | 
| 12 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |  | 
| 13 #include "chrome/browser/ui/views/autocomplete/autocomplete_result_view_model.h" |  | 
| 14 #include "ui/base/animation/animation_delegate.h" |  | 
| 15 #include "ui/base/animation/slide_animation.h" |  | 
| 16 #include "ui/gfx/font.h" |  | 
| 17 #include "ui/views/view.h" |  | 
| 18 #include "webkit/glue/window_open_disposition.h" |  | 
| 19 |  | 
| 20 class AutocompleteEditModel; |  | 
| 21 struct AutocompleteMatch; |  | 
| 22 class AutocompleteResultView; |  | 
| 23 class Profile; |  | 
| 24 |  | 
| 25 namespace views { |  | 
| 26 class BubbleBorder; |  | 
| 27 } |  | 
| 28 |  | 
| 29 // A view representing the contents of the autocomplete popup. |  | 
| 30 class AutocompletePopupContentsView : public views::View, |  | 
| 31                                       public AutocompleteResultViewModel, |  | 
| 32                                       public AutocompletePopupView, |  | 
| 33                                       public ui::AnimationDelegate { |  | 
| 34  public: |  | 
| 35   // Creates the appropriate type of omnibox dropdown for the |  | 
| 36   // current environment, e.g. desktop vs. touch optimized layout. |  | 
| 37   static AutocompletePopupContentsView* CreateForEnvironment( |  | 
| 38       const gfx::Font& font, |  | 
| 39       OmniboxView* omnibox_view, |  | 
| 40       AutocompleteEditModel* edit_model, |  | 
| 41       views::View* location_bar); |  | 
| 42 |  | 
| 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. |  | 
| 45   gfx::Rect GetPopupBounds() const; |  | 
| 46 |  | 
| 47   virtual void LayoutChildren(); |  | 
| 48 |  | 
| 49   // Overridden from AutocompletePopupView: |  | 
| 50   virtual bool IsOpen() const OVERRIDE; |  | 
| 51   virtual void InvalidateLine(size_t line) OVERRIDE; |  | 
| 52   virtual void UpdatePopupAppearance() OVERRIDE; |  | 
| 53   virtual gfx::Rect GetTargetBounds() OVERRIDE; |  | 
| 54   virtual void PaintUpdatesNow() OVERRIDE; |  | 
| 55   virtual void OnDragCanceled() OVERRIDE; |  | 
| 56 |  | 
| 57   // Overridden from AutocompleteResultViewModel: |  | 
| 58   virtual bool IsSelectedIndex(size_t index) const OVERRIDE; |  | 
| 59   virtual bool IsHoveredIndex(size_t index) const OVERRIDE; |  | 
| 60   virtual const SkBitmap* GetIconIfExtensionMatch(size_t index) const OVERRIDE; |  | 
| 61 |  | 
| 62   // Overridden from ui::AnimationDelegate: |  | 
| 63   virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |  | 
| 64 |  | 
| 65   // Overridden from views::View: |  | 
| 66   virtual void Layout() OVERRIDE; |  | 
| 67   virtual views::View* GetEventHandlerForPoint( |  | 
| 68       const gfx::Point& point) OVERRIDE; |  | 
| 69   virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |  | 
| 70   virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; |  | 
| 71   virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; |  | 
| 72   virtual void OnMouseCaptureLost() OVERRIDE; |  | 
| 73   virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; |  | 
| 74   virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |  | 
| 75   virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |  | 
| 76   virtual ui::GestureStatus OnGestureEvent( |  | 
| 77       const views::GestureEvent& event) OVERRIDE; |  | 
| 78 |  | 
| 79  protected: |  | 
| 80   AutocompletePopupContentsView(const gfx::Font& font, |  | 
| 81                                 OmniboxView* omnibox_view, |  | 
| 82                                 AutocompleteEditModel* edit_model, |  | 
| 83                                 views::View* location_bar); |  | 
| 84   virtual ~AutocompletePopupContentsView(); |  | 
| 85 |  | 
| 86   virtual void PaintResultViews(gfx::Canvas* canvas); |  | 
| 87 |  | 
| 88   // Calculates the height needed to show all the results in the model. |  | 
| 89   virtual int CalculatePopupHeight(); |  | 
| 90   virtual AutocompleteResultView* CreateResultView( |  | 
| 91       AutocompleteResultViewModel* model, |  | 
| 92       int model_index, |  | 
| 93       const gfx::Font& font, |  | 
| 94       const gfx::Font& bold_font); |  | 
| 95 |  | 
| 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<AutocompletePopupModel> model_; |  | 
| 105 |  | 
| 106  private: |  | 
| 107   class AutocompletePopupWidget; |  | 
| 108 |  | 
| 109   // Call immediately after construction. |  | 
| 110   void Init(); |  | 
| 111 |  | 
| 112   // Returns true if the model has a match at the specified index. |  | 
| 113   bool HasMatchAt(size_t index) const; |  | 
| 114 |  | 
| 115   // Returns the match at the specified index within the popup model. |  | 
| 116   const AutocompleteMatch& GetMatchAtIndex(size_t index) const; |  | 
| 117 |  | 
| 118   // Fill a path for the contents' roundrect. |bounding_rect| is the rect that |  | 
| 119   // bounds the path. |  | 
| 120   void MakeContentsPath(gfx::Path* path, const gfx::Rect& bounding_rect); |  | 
| 121 |  | 
| 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 |  | 
| 129   // provided disposition. |  | 
| 130   void OpenIndex(size_t index, WindowOpenDisposition disposition); |  | 
| 131 |  | 
| 132   // Find the index of the match under the given |point|, specified in window |  | 
| 133   // coordinates. Returns AutocompletePopupModel::kNoMatch if there isn't a |  | 
| 134   // match at the specified point. |  | 
| 135   size_t GetIndexForPoint(const gfx::Point& point); |  | 
| 136 |  | 
| 137   // Processes a located event (e.g. mouse/gesture) and sets the selection/hover |  | 
| 138   // state of a line in the list. |  | 
| 139   void UpdateLineEvent(const views::LocatedEvent& event, |  | 
| 140                        bool should_set_selected_line); |  | 
| 141 |  | 
| 142   // Opens an entry from the list depending on the event and the selected |  | 
| 143   // disposition. |  | 
| 144   void OpenSelectedLine(const views::LocatedEvent& event, |  | 
| 145                         WindowOpenDisposition disposition); |  | 
| 146 |  | 
| 147   // Returns the target bounds given the specified content height. |  | 
| 148   gfx::Rect CalculateTargetBounds(int h); |  | 
| 149 |  | 
| 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. |  | 
| 157   OmniboxView* omnibox_view_; |  | 
| 158 |  | 
| 159   Profile* profile_; |  | 
| 160 |  | 
| 161   // An object that the popup positions itself against. |  | 
| 162   views::View* location_bar_; |  | 
| 163 |  | 
| 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 |  | 
| 168   // by the edit that created us. |  | 
| 169   gfx::Font result_font_; |  | 
| 170 |  | 
| 171   // The font used for portions that match the input. |  | 
| 172   gfx::Font result_bold_font_; |  | 
| 173 |  | 
| 174   // 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 |  | 
| 176   // simply ignore all remaining drag events, and the eventual mouse release |  | 
| 177   // 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 |  | 
| 179   // erroneously ignore the next drag. |  | 
| 180   bool ignore_mouse_drag_; |  | 
| 181 |  | 
| 182   // The popup sizes vertically using an animation when the popup is getting |  | 
| 183   // shorter (not larger, that makes it look "slow"). |  | 
| 184   ui::SlideAnimation size_animation_; |  | 
| 185   gfx::Rect start_bounds_; |  | 
| 186   gfx::Rect target_bounds_; |  | 
| 187 |  | 
| 188   DISALLOW_COPY_AND_ASSIGN(AutocompletePopupContentsView); |  | 
| 189 }; |  | 
| 190 |  | 
| 191 #endif  // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_CONTENTS_VIEW
     _H_ |  | 
| OLD | NEW | 
|---|