| 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_RESULT_VIEW_H_ |  | 
| 6 #define CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ |  | 
| 7 #pragma once |  | 
| 8 |  | 
| 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |  | 
| 10 #include "third_party/skia/include/core/SkColor.h" |  | 
| 11 #include "ui/base/animation/animation_delegate.h" |  | 
| 12 #include "ui/base/animation/slide_animation.h" |  | 
| 13 #include "ui/gfx/font.h" |  | 
| 14 #include "ui/gfx/rect.h" |  | 
| 15 #include "ui/views/controls/image_view.h" |  | 
| 16 #include "ui/views/view.h" |  | 
| 17 |  | 
| 18 class AutocompleteResultViewModel; |  | 
| 19 |  | 
| 20 namespace gfx { |  | 
| 21 class Canvas; |  | 
| 22 } |  | 
| 23 |  | 
| 24 class AutocompleteResultView : public views::View, |  | 
| 25                                private ui::AnimationDelegate { |  | 
| 26  public: |  | 
| 27   // Keep these ordered from least dominant (normal) to most dominant |  | 
| 28   // (selected). |  | 
| 29   enum ResultViewState { |  | 
| 30     NORMAL = 0, |  | 
| 31     HOVERED, |  | 
| 32     SELECTED, |  | 
| 33     NUM_STATES |  | 
| 34   }; |  | 
| 35 |  | 
| 36   enum ColorKind { |  | 
| 37     BACKGROUND = 0, |  | 
| 38     TEXT, |  | 
| 39     DIMMED_TEXT, |  | 
| 40     URL, |  | 
| 41     DIVIDER, |  | 
| 42     NUM_KINDS |  | 
| 43   }; |  | 
| 44 |  | 
| 45   AutocompleteResultView(AutocompleteResultViewModel* model, |  | 
| 46                          int model_index, |  | 
| 47                          const gfx::Font& font, |  | 
| 48                          const gfx::Font& bold_font); |  | 
| 49   virtual ~AutocompleteResultView(); |  | 
| 50 |  | 
| 51   static SkColor GetColor(ResultViewState state, ColorKind kind); |  | 
| 52 |  | 
| 53   // Updates the match used to paint the contents of this result view. We copy |  | 
| 54   // the match so that we can continue to paint the last result even after the |  | 
| 55   // model has changed. |  | 
| 56   void SetMatch(const AutocompleteMatch& match); |  | 
| 57 |  | 
| 58   void ShowKeyword(bool show_keyword); |  | 
| 59 |  | 
| 60   void Invalidate(); |  | 
| 61 |  | 
| 62   // views::View: |  | 
| 63   virtual gfx::Size GetPreferredSize() OVERRIDE; |  | 
| 64 |  | 
| 65   ResultViewState GetState() const; |  | 
| 66 |  | 
| 67  protected: |  | 
| 68   virtual void PaintMatch(gfx::Canvas* canvas, |  | 
| 69                           const AutocompleteMatch& match, |  | 
| 70                           int x); |  | 
| 71 |  | 
| 72   // Returns the height of the text portion of the result view. In the base |  | 
| 73   // class, this is the height of one line of text. |  | 
| 74   virtual int GetTextHeight() const; |  | 
| 75 |  | 
| 76   // Draws the specified |text| into the canvas, using highlighting provided by |  | 
| 77   // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is |  | 
| 78   // added to all of the classifications. Returns the x position to the right |  | 
| 79   // of the string. |  | 
| 80   int DrawString(gfx::Canvas* canvas, |  | 
| 81                  const string16& text, |  | 
| 82                  const ACMatchClassifications& classifications, |  | 
| 83                  bool force_dim, |  | 
| 84                  int x, |  | 
| 85                  int y); |  | 
| 86 |  | 
| 87   const gfx::Rect& text_bounds() const { return text_bounds_; } |  | 
| 88 |  | 
| 89   void set_edge_item_padding(int value) { edge_item_padding_ = value; } |  | 
| 90   void set_item_padding(int value) { item_padding_ = value; } |  | 
| 91   void set_minimum_text_vertical_padding(int value) { |  | 
| 92     minimum_text_vertical_padding_ = value; |  | 
| 93   } |  | 
| 94 |  | 
| 95  private: |  | 
| 96   struct ClassificationData; |  | 
| 97   typedef std::vector<ClassificationData> Classifications; |  | 
| 98 |  | 
| 99   struct RunData; |  | 
| 100   typedef std::vector<RunData> Runs; |  | 
| 101 |  | 
| 102   // Predicate functions for use when sorting the runs. |  | 
| 103   static bool SortRunsLogically(const RunData& lhs, const RunData& rhs); |  | 
| 104   static bool SortRunsVisually(const RunData& lhs, const RunData& rhs); |  | 
| 105 |  | 
| 106   const SkBitmap* GetIcon() const; |  | 
| 107   const gfx::ImageSkia* GetKeywordIcon() const; |  | 
| 108 |  | 
| 109   // Elides |runs| to fit in |remaining_width|.  The runs in |runs| should be in |  | 
| 110   // logical order. |  | 
| 111   // |  | 
| 112   // When we need to elide a run, the ellipsis will be placed at the end of that |  | 
| 113   // run.  This means that if we elide a run whose visual direction is opposite |  | 
| 114   // that of the drawing context, the ellipsis will not be at the "end" of the |  | 
| 115   // drawn string.  For example, if in an LTR context we have the LTR run |  | 
| 116   // "LTR_STRING" and the RTL run "RTL_STRING", the unelided text would be drawn |  | 
| 117   // like: |  | 
| 118   //     LTR_STRING GNIRTS_LTR |  | 
| 119   // If we need to elide the RTL run, then it will be drawn like: |  | 
| 120   //     LTR_STRING ...RTS_LTR |  | 
| 121   // Instead of: |  | 
| 122   //     LTR_STRING RTS_LTR... |  | 
| 123   void Elide(Runs* runs, int remaining_width) const; |  | 
| 124 |  | 
| 125   // views::View: |  | 
| 126   virtual void Layout() OVERRIDE; |  | 
| 127   virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; |  | 
| 128   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |  | 
| 129 |  | 
| 130   // ui::AnimationDelegate: |  | 
| 131   virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |  | 
| 132 |  | 
| 133   static int default_icon_size_; |  | 
| 134 |  | 
| 135   // Default values cached here, may be overridden using the setters above. |  | 
| 136   int edge_item_padding_; |  | 
| 137   int item_padding_; |  | 
| 138   int minimum_text_vertical_padding_; |  | 
| 139 |  | 
| 140   // This row's model and model index. |  | 
| 141   AutocompleteResultViewModel* model_; |  | 
| 142   size_t model_index_; |  | 
| 143 |  | 
| 144   const gfx::Font normal_font_; |  | 
| 145   const gfx::Font bold_font_; |  | 
| 146 |  | 
| 147   // Width of the ellipsis in the normal font. |  | 
| 148   int ellipsis_width_; |  | 
| 149 |  | 
| 150   // A context used for mirroring regions. |  | 
| 151   class MirroringContext; |  | 
| 152   scoped_ptr<MirroringContext> mirroring_context_; |  | 
| 153 |  | 
| 154   AutocompleteMatch match_; |  | 
| 155 |  | 
| 156   gfx::Rect text_bounds_; |  | 
| 157   gfx::Rect icon_bounds_; |  | 
| 158 |  | 
| 159   gfx::Rect keyword_text_bounds_; |  | 
| 160   scoped_ptr<views::ImageView> keyword_icon_; |  | 
| 161 |  | 
| 162   scoped_ptr<ui::SlideAnimation> animation_; |  | 
| 163 |  | 
| 164   DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView); |  | 
| 165 }; |  | 
| 166 |  | 
| 167 #endif  // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ |  | 
| OLD | NEW | 
|---|