| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright (c) 2006-2008 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_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_WIN_H_ |  | 
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_WIN_H_ |  | 
| 7 |  | 
| 8 #include <atlbase.h> |  | 
| 9 #include <atlapp.h> |  | 
| 10 #include <atlcrack.h> |  | 
| 11 #include <atlmisc.h> |  | 
| 12 |  | 
| 13 #include <string> |  | 
| 14 |  | 
| 15 #include "app/gfx/font.h" |  | 
| 16 #include "base/scoped_ptr.h" |  | 
| 17 #include "base/win_util.h" |  | 
| 18 #include "chrome/browser/autocomplete/autocomplete.h" |  | 
| 19 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" |  | 
| 20 #include "webkit/glue/window_open_disposition.h" |  | 
| 21 |  | 
| 22 class AutocompletePopupModel; |  | 
| 23 class AutocompleteEditModel; |  | 
| 24 class AutocompleteEditViewWin; |  | 
| 25 class Profile; |  | 
| 26 class SkBitmap; |  | 
| 27 |  | 
| 28 #define AUTOCOMPLETEPOPUPVIEW_CLASSNAME L"Chrome_AutocompletePopupView" |  | 
| 29 |  | 
| 30 // This class implements a popup window used to display autocomplete results. |  | 
| 31 class AutocompletePopupViewWin |  | 
| 32     : public CWindowImpl<AutocompletePopupViewWin, CWindow, CControlWinTraits>, |  | 
| 33       public AutocompletePopupView { |  | 
| 34  public: |  | 
| 35   DECLARE_WND_CLASS_EX(AUTOCOMPLETEPOPUPVIEW_CLASSNAME, |  | 
| 36                        ((win_util::GetWinVersion() < win_util::WINVERSION_XP) ? |  | 
| 37                            0 : CS_DROPSHADOW), COLOR_WINDOW) |  | 
| 38 |  | 
| 39   BEGIN_MSG_MAP(AutocompletePopupViewWin) |  | 
| 40     MSG_WM_ERASEBKGND(OnEraseBkgnd) |  | 
| 41     MSG_WM_LBUTTONDOWN(OnLButtonDown) |  | 
| 42     MSG_WM_MBUTTONDOWN(OnMButtonDown) |  | 
| 43     MSG_WM_LBUTTONUP(OnLButtonUp) |  | 
| 44     MSG_WM_MBUTTONUP(OnMButtonUp) |  | 
| 45     MSG_WM_MOUSEACTIVATE(OnMouseActivate) |  | 
| 46     MSG_WM_MOUSELEAVE(OnMouseLeave) |  | 
| 47     MSG_WM_MOUSEMOVE(OnMouseMove) |  | 
| 48     MSG_WM_PAINT(OnPaint) |  | 
| 49   END_MSG_MAP() |  | 
| 50 |  | 
| 51   AutocompletePopupViewWin(const gfx::Font& font, |  | 
| 52                            AutocompleteEditViewWin* edit_view, |  | 
| 53                            AutocompleteEditModel* edit_model, |  | 
| 54                            Profile* profile); |  | 
| 55 |  | 
| 56   // Returns true if the popup is currently open. |  | 
| 57   virtual bool IsOpen() const { return m_hWnd != NULL; } |  | 
| 58 |  | 
| 59   // Invalidates one line of the autocomplete popup. |  | 
| 60   virtual void InvalidateLine(size_t line); |  | 
| 61 |  | 
| 62   // Redraws the popup window to match any changes in the result set; this may |  | 
| 63   // mean opening or closing the window. |  | 
| 64   virtual void UpdatePopupAppearance(); |  | 
| 65 |  | 
| 66   // Called by the model when hover is enabled or disabled. |  | 
| 67   virtual void OnHoverEnabledOrDisabled(bool disabled); |  | 
| 68 |  | 
| 69   virtual void PaintUpdatesNow() { UpdateWindow(); } |  | 
| 70 |  | 
| 71   virtual AutocompletePopupModel* GetModel() { return model_.get(); } |  | 
| 72 |  | 
| 73  private: |  | 
| 74   class MirroringContext; |  | 
| 75 |  | 
| 76   // Caches GDI objects and information for drawing. |  | 
| 77   struct DrawLineInfo { |  | 
| 78     enum LineStatus { |  | 
| 79       NORMAL = 0, |  | 
| 80       HOVERED, |  | 
| 81       SELECTED, |  | 
| 82       MAX_STATUS_ENTRIES |  | 
| 83     }; |  | 
| 84 |  | 
| 85     explicit DrawLineInfo(const gfx::Font& font); |  | 
| 86     ~DrawLineInfo(); |  | 
| 87 |  | 
| 88     static COLORREF AlphaBlend(COLORREF foreground, |  | 
| 89                                COLORREF background, |  | 
| 90                                BYTE alpha); |  | 
| 91 |  | 
| 92     static const wchar_t ellipsis_str[]; |  | 
| 93 |  | 
| 94     gfx::Font regular_font;  // Fonts used for rendering AutocompleteMatches. |  | 
| 95     gfx::Font bold_font; |  | 
| 96     int font_height;          // Height (in pixels) of a line of text w/o |  | 
| 97                               // padding. |  | 
| 98     int line_height;          // Height (in pixels) of a line of text w/padding. |  | 
| 99     int ave_char_width;       // Width (in pixels) of an average character of |  | 
| 100                               // the regular font. |  | 
| 101     int ellipsis_width;       // Width (in pixels) of the ellipsis_str. |  | 
| 102 |  | 
| 103     // colors |  | 
| 104     COLORREF background_colors[MAX_STATUS_ENTRIES]; |  | 
| 105     COLORREF text_colors[MAX_STATUS_ENTRIES]; |  | 
| 106     COLORREF url_colors[MAX_STATUS_ENTRIES]; |  | 
| 107 |  | 
| 108     // brushes |  | 
| 109     HBRUSH brushes[MAX_STATUS_ENTRIES]; |  | 
| 110 |  | 
| 111    private: |  | 
| 112     static double LuminosityContrast(COLORREF color1, COLORREF color2); |  | 
| 113     static double Luminosity(COLORREF color); |  | 
| 114   }; |  | 
| 115 |  | 
| 116   // message handlers |  | 
| 117   LRESULT OnEraseBkgnd(HDC hdc) { |  | 
| 118     // We do all needed erasing ourselves in OnPaint, so the only thing that |  | 
| 119     // WM_ERASEBKGND will do is cause flicker.  Disable it by just returning |  | 
| 120     // nonzero here ("erase completed") without doing anything. |  | 
| 121     return 1; |  | 
| 122   } |  | 
| 123   void OnLButtonDown(UINT keys, const CPoint& point); |  | 
| 124   void OnMButtonDown(UINT keys, const CPoint& point); |  | 
| 125   void OnLButtonUp(UINT keys, const CPoint& point); |  | 
| 126   void OnMButtonUp(UINT keys, const CPoint& point); |  | 
| 127   LRESULT OnMouseActivate(HWND window, UINT hit_test, UINT mouse_message); |  | 
| 128   void OnMouseLeave(); |  | 
| 129   void OnMouseMove(UINT keys, const CPoint& point); |  | 
| 130   void OnPaint(HDC hdc); |  | 
| 131 |  | 
| 132   // Called by On*ButtonUp() to do the actual work of handling a button |  | 
| 133   // release.  Opens the item at the given coordinate, using the supplied |  | 
| 134   // disposition. |  | 
| 135   void OnButtonUp(const CPoint& point, WindowOpenDisposition disposition); |  | 
| 136 |  | 
| 137   // Gives the topmost y coordinate within |line|, which should be within the |  | 
| 138   // range of valid lines. |  | 
| 139   int LineTopPixel(size_t line) const; |  | 
| 140 |  | 
| 141   // Converts the given y-coordinate to a line.  Due to drawing slop (window |  | 
| 142   // borders, etc.), |y| might be within the window but outside the range of |  | 
| 143   // pixels which correspond to lines; in this case the result will be clamped, |  | 
| 144   // i.e., the top and bottom lines will be treated as extending to the top and |  | 
| 145   // bottom edges of the window, respectively. |  | 
| 146   size_t PixelToLine(int y) const; |  | 
| 147 |  | 
| 148   // Draws a light border around the inside of the window with the given client |  | 
| 149   // rectangle and DC. |  | 
| 150   void DrawBorder(const RECT& rc, HDC dc); |  | 
| 151 |  | 
| 152   // Draws a single run of text with a particular style.  Handles both LTR and |  | 
| 153   // RTL text as well as eliding.  Returns the width, in pixels, of the string |  | 
| 154   // as it was actually displayed. |  | 
| 155   int DrawString(HDC dc, |  | 
| 156                  int x, |  | 
| 157                  int y, |  | 
| 158                  int max_x, |  | 
| 159                  const wchar_t* text, |  | 
| 160                  int length, |  | 
| 161                  int style, |  | 
| 162                  const DrawLineInfo::LineStatus status, |  | 
| 163                  const MirroringContext* context, |  | 
| 164                  bool text_direction_is_rtl) const; |  | 
| 165 |  | 
| 166   // Draws a string from the autocomplete controller which can have specially |  | 
| 167   // marked "match" portions. |  | 
| 168   void DrawMatchFragments(HDC dc, |  | 
| 169                           const std::wstring& text, |  | 
| 170                           const ACMatchClassifications& classifications, |  | 
| 171                           int x, |  | 
| 172                           int y, |  | 
| 173                           int max_x, |  | 
| 174                           DrawLineInfo::LineStatus status) const; |  | 
| 175 |  | 
| 176   // Draws one line of the text in the box. |  | 
| 177   void DrawEntry(HDC dc, |  | 
| 178                  const RECT& client_rect, |  | 
| 179                  size_t line, |  | 
| 180                  DrawLineInfo::LineStatus status, |  | 
| 181                  bool all_descriptions_empty, |  | 
| 182                  bool starred) const; |  | 
| 183 |  | 
| 184   // Draws the star at the specified location |  | 
| 185   void DrawStar(HDC dc, int x, int y) const; |  | 
| 186 |  | 
| 187   scoped_ptr<AutocompletePopupModel> model_; |  | 
| 188 |  | 
| 189   AutocompleteEditViewWin* edit_view_; |  | 
| 190 |  | 
| 191   // Cached GDI information for drawing. |  | 
| 192   DrawLineInfo line_info_; |  | 
| 193 |  | 
| 194   // Bitmap for the star.  This is owned by the ResourceBundle. |  | 
| 195   SkBitmap* star_; |  | 
| 196 |  | 
| 197   // A context used for mirroring regions. |  | 
| 198   scoped_ptr<MirroringContext> mirroring_context_; |  | 
| 199 |  | 
| 200   // When hovered_line_ is kNoMatch, this holds the screen coordinates of the |  | 
| 201   // mouse position when hover tracking was turned off.  If the mouse moves to a |  | 
| 202   // point over the popup that has different coordinates, hover tracking will be |  | 
| 203   // re-enabled.  When hovered_line_ is a valid line, the value here is |  | 
| 204   // out-of-date and should be ignored. |  | 
| 205   CPoint last_hover_coordinates_; |  | 
| 206 |  | 
| 207   DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewWin); |  | 
| 208 }; |  | 
| 209 |  | 
| 210 #endif  // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_VIEW_WIN_H_ |  | 
| OLD | NEW | 
|---|