OLD | NEW |
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_VIEW_WIN_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_WIN_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_WIN_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_WIN_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlapp.h> | 9 #include <atlapp.h> |
10 #include <atlcrack.h> | 10 #include <atlcrack.h> |
11 #include <atlctrls.h> | 11 #include <atlctrls.h> |
12 #include <atlmisc.h> | 12 #include <atlmisc.h> |
13 #include <peninputpanel.h> | 13 #include <peninputpanel.h> |
14 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl. | 14 #include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl. |
15 | 15 |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/win/scoped_comptr.h" | 17 #include "base/win/scoped_comptr.h" |
18 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 18 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
19 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 19 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
20 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" | 20 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
21 #include "ui/base/models/simple_menu_model.h" | 21 #include "ui/base/models/simple_menu_model.h" |
22 #include "ui/base/win/extra_sdk_defines.h" | 22 #include "ui/base/win/extra_sdk_defines.h" |
23 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
24 #include "webkit/glue/window_open_disposition.h" | 24 #include "webkit/glue/window_open_disposition.h" |
25 | 25 |
26 class LocationBarView; | 26 class LocationBarView; |
27 class OmniboxEditController; | |
28 class OmniboxEditModel; | |
29 class OmniboxPopupView; | 27 class OmniboxPopupView; |
30 | 28 |
31 namespace views { | 29 namespace views { |
32 class MenuRunner; | 30 class MenuRunner; |
33 class NativeViewHost; | 31 class NativeViewHost; |
34 class View; | 32 class View; |
35 } | 33 } |
36 | 34 |
37 // Provides the implementation of an edit control with a drop-down | 35 // Provides the implementation of an edit control with a drop-down |
38 // autocomplete box. The box itself is implemented in autocomplete_popup.cc | 36 // autocomplete box. The box itself is implemented in autocomplete_popup.cc |
(...skipping 29 matching lines...) Expand all Loading... |
68 views::View* popup_parent_view); | 66 views::View* popup_parent_view); |
69 ~OmniboxViewWin(); | 67 ~OmniboxViewWin(); |
70 | 68 |
71 // Gets the relative window for the specified native view. | 69 // Gets the relative window for the specified native view. |
72 static gfx::NativeView GetRelativeWindowForNativeView( | 70 static gfx::NativeView GetRelativeWindowForNativeView( |
73 gfx::NativeView edit_native_view); | 71 gfx::NativeView edit_native_view); |
74 | 72 |
75 views::View* parent_view() const; | 73 views::View* parent_view() const; |
76 | 74 |
77 // OmniboxView: | 75 // OmniboxView: |
78 virtual OmniboxEditModel* model() OVERRIDE { return model_.get(); } | |
79 virtual const OmniboxEditModel* model() const OVERRIDE { | |
80 return model_.get(); | |
81 } | |
82 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; | 76 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; |
83 virtual void Update( | 77 virtual void Update( |
84 const content::WebContents* tab_for_state_restoring) OVERRIDE; | 78 const content::WebContents* tab_for_state_restoring) OVERRIDE; |
85 virtual void OpenMatch(const AutocompleteMatch& match, | 79 virtual void OpenMatch(const AutocompleteMatch& match, |
86 WindowOpenDisposition disposition, | 80 WindowOpenDisposition disposition, |
87 const GURL& alternate_nav_url, | 81 const GURL& alternate_nav_url, |
88 size_t index) OVERRIDE; | 82 size_t index) OVERRIDE; |
89 virtual string16 GetText() const OVERRIDE; | 83 virtual string16 GetText() const OVERRIDE; |
90 virtual bool IsEditingOrEmpty() const OVERRIDE; | |
91 virtual int GetIcon() const OVERRIDE; | |
92 virtual void SetUserText(const string16& text) OVERRIDE; | |
93 virtual void SetUserText(const string16& text, | 84 virtual void SetUserText(const string16& text, |
94 const string16& display_text, | 85 const string16& display_text, |
95 bool update_popup) OVERRIDE; | 86 bool update_popup) OVERRIDE; |
96 virtual void SetWindowTextAndCaretPos(const string16& text, | 87 virtual void SetWindowTextAndCaretPos(const string16& text, |
97 size_t caret_pos, | 88 size_t caret_pos, |
98 bool update_popup, | 89 bool update_popup, |
99 bool notify_text_changed) OVERRIDE; | 90 bool notify_text_changed) OVERRIDE; |
100 virtual void SetForcedQuery() OVERRIDE; | 91 virtual void SetForcedQuery() OVERRIDE; |
101 virtual bool IsSelectAll() const OVERRIDE; | 92 virtual bool IsSelectAll() const OVERRIDE; |
102 virtual bool DeleteAtEndPressed() OVERRIDE; | 93 virtual bool DeleteAtEndPressed() OVERRIDE; |
103 virtual void GetSelectionBounds(string16::size_type* start, | 94 virtual void GetSelectionBounds(string16::size_type* start, |
104 string16::size_type* end) const OVERRIDE; | 95 string16::size_type* end) const OVERRIDE; |
105 virtual void SelectAll(bool reversed) OVERRIDE; | 96 virtual void SelectAll(bool reversed) OVERRIDE; |
106 virtual void RevertAll() OVERRIDE; | 97 virtual void RevertAll() OVERRIDE; |
107 virtual void UpdatePopup() OVERRIDE; | 98 virtual void UpdatePopup() OVERRIDE; |
108 virtual void ClosePopup() OVERRIDE; | |
109 virtual void SetFocus() OVERRIDE; | 99 virtual void SetFocus() OVERRIDE; |
110 virtual void OnTemporaryTextMaybeChanged( | 100 virtual void OnTemporaryTextMaybeChanged( |
111 const string16& display_text, | 101 const string16& display_text, |
112 bool save_original_selection) OVERRIDE; | 102 bool save_original_selection) OVERRIDE; |
113 virtual bool OnInlineAutocompleteTextMaybeChanged( | 103 virtual bool OnInlineAutocompleteTextMaybeChanged( |
114 const string16& display_text, size_t user_text_length) OVERRIDE; | 104 const string16& display_text, size_t user_text_length) OVERRIDE; |
115 virtual void OnRevertTemporaryText() OVERRIDE; | 105 virtual void OnRevertTemporaryText() OVERRIDE; |
116 virtual void OnBeforePossibleChange() OVERRIDE; | 106 virtual void OnBeforePossibleChange() OVERRIDE; |
117 virtual bool OnAfterPossibleChange() OVERRIDE; | 107 virtual bool OnAfterPossibleChange() OVERRIDE; |
118 virtual gfx::NativeView GetNativeView() const OVERRIDE; | 108 virtual gfx::NativeView GetNativeView() const OVERRIDE; |
119 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; | 109 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; |
120 virtual CommandUpdater* GetCommandUpdater() OVERRIDE; | |
121 virtual void SetInstantSuggestion(const string16& suggestion, | 110 virtual void SetInstantSuggestion(const string16& suggestion, |
122 bool animate_to_complete) OVERRIDE; | 111 bool animate_to_complete) OVERRIDE; |
123 virtual int TextWidth() const OVERRIDE; | 112 virtual int TextWidth() const OVERRIDE; |
124 virtual string16 GetInstantSuggestion() const OVERRIDE; | 113 virtual string16 GetInstantSuggestion() const OVERRIDE; |
125 virtual bool IsImeComposing() const OVERRIDE; | 114 virtual bool IsImeComposing() const OVERRIDE; |
126 virtual int GetMaxEditWidth(int entry_width) const OVERRIDE; | 115 virtual int GetMaxEditWidth(int entry_width) const OVERRIDE; |
127 virtual views::View* AddToView(views::View* parent) OVERRIDE; | 116 virtual views::View* AddToView(views::View* parent) OVERRIDE; |
128 virtual int OnPerformDrop(const views::DropTargetEvent& event) OVERRIDE; | 117 virtual int OnPerformDrop(const views::DropTargetEvent& event) OVERRIDE; |
129 virtual gfx::Font GetFont() OVERRIDE; | 118 virtual gfx::Font GetFont() OVERRIDE; |
130 virtual int WidthOfTextAfterCursor() OVERRIDE; | 119 virtual int WidthOfTextAfterCursor() OVERRIDE; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 // ui::SimpleMenuModel::Delegate | 182 // ui::SimpleMenuModel::Delegate |
194 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 183 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
195 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 184 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
196 virtual bool GetAcceleratorForCommandId( | 185 virtual bool GetAcceleratorForCommandId( |
197 int command_id, | 186 int command_id, |
198 ui::Accelerator* accelerator) OVERRIDE; | 187 ui::Accelerator* accelerator) OVERRIDE; |
199 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE; | 188 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE; |
200 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE; | 189 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE; |
201 virtual void ExecuteCommand(int command_id) OVERRIDE; | 190 virtual void ExecuteCommand(int command_id) OVERRIDE; |
202 | 191 |
203 // Returns true if the caret is at the end of the content. | |
204 bool IsCaretAtEnd() const; | |
205 | |
206 private: | 192 private: |
207 enum MouseButton { | 193 enum MouseButton { |
208 kLeft = 0, | 194 kLeft = 0, |
209 kRight = 1, | 195 kRight = 1, |
210 }; | 196 }; |
211 | 197 |
212 // This object freezes repainting of the edit until the object is destroyed. | 198 // This object freezes repainting of the edit until the object is destroyed. |
213 // Some methods of the CRichEditCtrl draw synchronously to the screen. If we | 199 // Some methods of the CRichEditCtrl draw synchronously to the screen. If we |
214 // don't freeze, the user will see a rapid series of calls to these as | 200 // don't freeze, the user will see a rapid series of calls to these as |
215 // flickers. | 201 // flickers. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // clipped to be within the horizontal bounds of the visible text. | 313 // clipped to be within the horizontal bounds of the visible text. |
328 // | 314 // |
329 // This is used in our mouse handlers to work around quirky behaviors of the | 315 // This is used in our mouse handlers to work around quirky behaviors of the |
330 // underlying CRichEditCtrl like not supporting triple-click when the user | 316 // underlying CRichEditCtrl like not supporting triple-click when the user |
331 // doesn't click on the text itself. | 317 // doesn't click on the text itself. |
332 // | 318 // |
333 // |is_triple_click| should be true iff this is the third click of a triple | 319 // |is_triple_click| should be true iff this is the third click of a triple |
334 // click. Sadly, we need to clip slightly differently in this case. | 320 // click. Sadly, we need to clip slightly differently in this case. |
335 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const; | 321 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const; |
336 | 322 |
| 323 virtual int GetOmniboxTextLength() const OVERRIDE; |
| 324 |
337 // Parses the contents of the control for the scheme and the host name. | 325 // Parses the contents of the control for the scheme and the host name. |
338 // Highlights the scheme in green or red depending on it security level. | 326 // Highlights the scheme in green or red depending on it security level. |
339 // If a host name is found, it makes it visually stronger. | 327 // If a host name is found, it makes it visually stronger. |
340 void EmphasizeURLComponents(); | 328 virtual void EmphasizeURLComponents() OVERRIDE; |
341 | 329 |
342 // Erases the portion of the selection in the font's y-adjustment area. For | 330 // Erases the portion of the selection in the font's y-adjustment area. For |
343 // some reason the edit draws the selection rect here even though it's not | 331 // some reason the edit draws the selection rect here even though it's not |
344 // part of the font. | 332 // part of the font. |
345 void EraseTopOfSelection(CDC* dc, | 333 void EraseTopOfSelection(CDC* dc, |
346 const CRect& client_rect, | 334 const CRect& client_rect, |
347 const CRect& paint_clip_rect); | 335 const CRect& paint_clip_rect); |
348 | 336 |
349 // Draws a slash across the scheme if desired. | 337 // Draws a slash across the scheme if desired. |
350 void DrawSlashForInsecureScheme(HDC hdc, | 338 void DrawSlashForInsecureScheme(HDC hdc, |
351 const CRect& client_rect, | 339 const CRect& client_rect, |
352 const CRect& paint_clip_rect); | 340 const CRect& paint_clip_rect); |
353 | 341 |
354 // Renders the drop highlight. | 342 // Renders the drop highlight. |
355 void DrawDropHighlight(HDC hdc, | 343 void DrawDropHighlight(HDC hdc, |
356 const CRect& client_rect, | 344 const CRect& client_rect, |
357 const CRect& paint_clip_rect); | 345 const CRect& paint_clip_rect); |
358 | 346 |
359 // Internally invoked whenever the text changes in some way. | 347 // Internally invoked whenever the text changes in some way. |
360 void TextChanged(); | 348 void TextChanged() OVERRIDE; |
361 | 349 |
362 // Getter for the text_object_model_. Note that the pointer returned here is | 350 // Getter for the text_object_model_. Note that the pointer returned here is |
363 // only valid as long as the AutocompleteEdit is still alive. Also, if the | 351 // only valid as long as the AutocompleteEdit is still alive. Also, if the |
364 // underlying call fails, this may return NULL. | 352 // underlying call fails, this may return NULL. |
365 ITextDocument* GetTextObjectModel() const; | 353 ITextDocument* GetTextObjectModel() const; |
366 | 354 |
367 // Invoked during a mouse move. As necessary starts a drag and drop session. | 355 // Invoked during a mouse move. As necessary starts a drag and drop session. |
368 void StartDragIfNecessary(const CPoint& point); | 356 void StartDragIfNecessary(const CPoint& point); |
369 | 357 |
370 // Invoked during a mouse down. If the mouse location is over the selection | 358 // Invoked during a mouse down. If the mouse location is over the selection |
(...skipping 19 matching lines...) Expand all Loading... |
390 int WidthNeededToDisplay(const string16& text) const; | 378 int WidthNeededToDisplay(const string16& text) const; |
391 | 379 |
392 // Real implementation of OnAfterPossibleChange() method. | 380 // Real implementation of OnAfterPossibleChange() method. |
393 // If |force_text_changed| is true, then the text_changed code will always be | 381 // If |force_text_changed| is true, then the text_changed code will always be |
394 // triggerred no matter if the text is actually changed or not. | 382 // triggerred no matter if the text is actually changed or not. |
395 bool OnAfterPossibleChangeInternal(bool force_text_changed); | 383 bool OnAfterPossibleChangeInternal(bool force_text_changed); |
396 | 384 |
397 // Common implementation for performing a drop on the edit view. | 385 // Common implementation for performing a drop on the edit view. |
398 int OnPerformDropImpl(const views::DropTargetEvent& event, bool in_drag); | 386 int OnPerformDropImpl(const views::DropTargetEvent& event, bool in_drag); |
399 | 387 |
400 scoped_ptr<OmniboxEditModel> model_; | |
401 | |
402 scoped_ptr<OmniboxPopupView> popup_view_; | 388 scoped_ptr<OmniboxPopupView> popup_view_; |
403 | 389 |
404 OmniboxEditController* controller_; | |
405 | |
406 // The parent view for the edit, used to align the popup and for | 390 // The parent view for the edit, used to align the popup and for |
407 // accessibility. | 391 // accessibility. |
408 LocationBarView* parent_view_; | 392 LocationBarView* parent_view_; |
409 | 393 |
410 ToolbarModel* toolbar_model_; | |
411 | |
412 // The object that handles additional command functionality exposed on the | |
413 // edit, such as invoking the keyword editor. | |
414 CommandUpdater* command_updater_; | |
415 | |
416 // When true, the location bar view is read only and also is has a slightly | 394 // When true, the location bar view is read only and also is has a slightly |
417 // different presentation (font size / color). This is used for popups. | 395 // different presentation (font size / color). This is used for popups. |
418 bool popup_window_mode_; | 396 bool popup_window_mode_; |
419 | 397 |
420 // True if we should prevent attempts to make the window visible when we | 398 // True if we should prevent attempts to make the window visible when we |
421 // handle WM_WINDOWPOSCHANGING. While toggling fullscreen mode, the main | 399 // handle WM_WINDOWPOSCHANGING. While toggling fullscreen mode, the main |
422 // window is hidden, and if the edit is shown it will draw over the main | 400 // window is hidden, and if the edit is shown it will draw over the main |
423 // window when that window reappears. | 401 // window when that window reappears. |
424 bool force_hidden_; | 402 bool force_hidden_; |
425 | 403 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 // Instance of accessibility information and handling. | 499 // Instance of accessibility information and handling. |
522 mutable base::win::ScopedComPtr<IAccessible> autocomplete_accessibility_; | 500 mutable base::win::ScopedComPtr<IAccessible> autocomplete_accessibility_; |
523 | 501 |
524 // The native view host. | 502 // The native view host. |
525 views::NativeViewHost* native_view_host_; | 503 views::NativeViewHost* native_view_host_; |
526 | 504 |
527 DISALLOW_COPY_AND_ASSIGN(OmniboxViewWin); | 505 DISALLOW_COPY_AND_ASSIGN(OmniboxViewWin); |
528 }; | 506 }; |
529 | 507 |
530 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_WIN_H_ | 508 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_WIN_H_ |
OLD | NEW |