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

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

Issue 10810062: Moving common code into OmniboxView from OmniboxView* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename GetTextLength to allow reasoning about win version" Created 8 years, 5 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_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
39 // This file implements the edit box and management for the popup. 37 // This file implements the edit box and management for the popup.
40 class OmniboxViewWin 38 typedef CWindowImpl<OmniboxViewWin, CRichEditCtrl,
41 : public CWindowImpl<OmniboxViewWin, 39 CWinTraits<WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL |
42 CRichEditCtrl, 40 ES_NOHIDESEL> > CWindowBase;
43 CWinTraits<WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | 41 class OmniboxViewWin : public CWindowBase,
44 ES_NOHIDESEL> >, 42 public CRichEditCommands<OmniboxViewWin>,
45 public CRichEditCommands<OmniboxViewWin>, 43 public ui::SimpleMenuModel::Delegate,
46 public ui::SimpleMenuModel::Delegate, 44 public OmniboxView {
47 public OmniboxView {
48 public: 45 public:
49 struct State { 46 struct State {
50 State(const CHARRANGE& selection, 47 State(const CHARRANGE& selection,
51 const CHARRANGE& saved_selection_for_focus_change) 48 const CHARRANGE& saved_selection_for_focus_change)
52 : selection(selection), 49 : selection(selection),
53 saved_selection_for_focus_change(saved_selection_for_focus_change) { 50 saved_selection_for_focus_change(saved_selection_for_focus_change) {
54 } 51 }
55 52
56 const CHARRANGE selection; 53 const CHARRANGE selection;
57 const CHARRANGE saved_selection_for_focus_change; 54 const CHARRANGE saved_selection_for_focus_change;
(...skipping 10 matching lines...) Expand all
68 views::View* popup_parent_view); 65 views::View* popup_parent_view);
69 ~OmniboxViewWin(); 66 ~OmniboxViewWin();
70 67
71 // Gets the relative window for the specified native view. 68 // Gets the relative window for the specified native view.
72 static gfx::NativeView GetRelativeWindowForNativeView( 69 static gfx::NativeView GetRelativeWindowForNativeView(
73 gfx::NativeView edit_native_view); 70 gfx::NativeView edit_native_view);
74 71
75 views::View* parent_view() const; 72 views::View* parent_view() const;
76 73
77 // OmniboxView: 74 // 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; 75 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE;
83 virtual void Update( 76 virtual void Update(
84 const content::WebContents* tab_for_state_restoring) OVERRIDE; 77 const content::WebContents* tab_for_state_restoring) OVERRIDE;
85 virtual void OpenMatch(const AutocompleteMatch& match, 78 virtual void OpenMatch(const AutocompleteMatch& match,
86 WindowOpenDisposition disposition, 79 WindowOpenDisposition disposition,
87 const GURL& alternate_nav_url, 80 const GURL& alternate_nav_url,
88 size_t index) OVERRIDE; 81 size_t index) OVERRIDE;
89 virtual string16 GetText() const OVERRIDE; 82 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, 83 virtual void SetUserText(const string16& text,
94 const string16& display_text, 84 const string16& display_text,
95 bool update_popup) OVERRIDE; 85 bool update_popup) OVERRIDE;
96 virtual void SetWindowTextAndCaretPos(const string16& text, 86 virtual void SetWindowTextAndCaretPos(const string16& text,
97 size_t caret_pos, 87 size_t caret_pos,
98 bool update_popup, 88 bool update_popup,
99 bool notify_text_changed) OVERRIDE; 89 bool notify_text_changed) OVERRIDE;
100 virtual void SetForcedQuery() OVERRIDE; 90 virtual void SetForcedQuery() OVERRIDE;
101 virtual bool IsSelectAll() const OVERRIDE; 91 virtual bool IsSelectAll() const OVERRIDE;
102 virtual bool DeleteAtEndPressed() OVERRIDE; 92 virtual bool DeleteAtEndPressed() OVERRIDE;
103 virtual void GetSelectionBounds(string16::size_type* start, 93 virtual void GetSelectionBounds(string16::size_type* start,
104 string16::size_type* end) const OVERRIDE; 94 string16::size_type* end) const OVERRIDE;
105 virtual void SelectAll(bool reversed) OVERRIDE; 95 virtual void SelectAll(bool reversed) OVERRIDE;
106 virtual void RevertAll() OVERRIDE; 96 virtual void RevertAll() OVERRIDE;
107 virtual void UpdatePopup() OVERRIDE; 97 virtual void UpdatePopup() OVERRIDE;
108 virtual void ClosePopup() OVERRIDE;
109 virtual void SetFocus() OVERRIDE; 98 virtual void SetFocus() OVERRIDE;
110 virtual void OnTemporaryTextMaybeChanged( 99 virtual void OnTemporaryTextMaybeChanged(
111 const string16& display_text, 100 const string16& display_text,
112 bool save_original_selection) OVERRIDE; 101 bool save_original_selection) OVERRIDE;
113 virtual bool OnInlineAutocompleteTextMaybeChanged( 102 virtual bool OnInlineAutocompleteTextMaybeChanged(
114 const string16& display_text, size_t user_text_length) OVERRIDE; 103 const string16& display_text, size_t user_text_length) OVERRIDE;
115 virtual void OnRevertTemporaryText() OVERRIDE; 104 virtual void OnRevertTemporaryText() OVERRIDE;
116 virtual void OnBeforePossibleChange() OVERRIDE; 105 virtual void OnBeforePossibleChange() OVERRIDE;
117 virtual bool OnAfterPossibleChange() OVERRIDE; 106 virtual bool OnAfterPossibleChange() OVERRIDE;
118 virtual gfx::NativeView GetNativeView() const OVERRIDE; 107 virtual gfx::NativeView GetNativeView() const OVERRIDE;
119 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; 108 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE;
120 virtual CommandUpdater* GetCommandUpdater() OVERRIDE;
121 virtual void SetInstantSuggestion(const string16& suggestion, 109 virtual void SetInstantSuggestion(const string16& suggestion,
122 bool animate_to_complete) OVERRIDE; 110 bool animate_to_complete) OVERRIDE;
123 virtual int TextWidth() const OVERRIDE; 111 virtual int TextWidth() const OVERRIDE;
124 virtual string16 GetInstantSuggestion() const OVERRIDE; 112 virtual string16 GetInstantSuggestion() const OVERRIDE;
125 virtual bool IsImeComposing() const OVERRIDE; 113 virtual bool IsImeComposing() const OVERRIDE;
126 virtual int GetMaxEditWidth(int entry_width) const OVERRIDE; 114 virtual int GetMaxEditWidth(int entry_width) const OVERRIDE;
127 virtual views::View* AddToView(views::View* parent) OVERRIDE; 115 virtual views::View* AddToView(views::View* parent) OVERRIDE;
128 virtual int OnPerformDrop(const views::DropTargetEvent& event) OVERRIDE; 116 virtual int OnPerformDrop(const views::DropTargetEvent& event) OVERRIDE;
129 virtual gfx::Font GetFont() OVERRIDE; 117 virtual gfx::Font GetFont() OVERRIDE;
130 virtual int WidthOfTextAfterCursor() OVERRIDE; 118 virtual int WidthOfTextAfterCursor() OVERRIDE;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // ui::SimpleMenuModel::Delegate 181 // ui::SimpleMenuModel::Delegate
194 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 182 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
195 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 183 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
196 virtual bool GetAcceleratorForCommandId( 184 virtual bool GetAcceleratorForCommandId(
197 int command_id, 185 int command_id,
198 ui::Accelerator* accelerator) OVERRIDE; 186 ui::Accelerator* accelerator) OVERRIDE;
199 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE; 187 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
200 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE; 188 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE;
201 virtual void ExecuteCommand(int command_id) OVERRIDE; 189 virtual void ExecuteCommand(int command_id) OVERRIDE;
202 190
203 // Returns true if the caret is at the end of the content.
204 bool IsCaretAtEnd() const;
205
206 private: 191 private:
207 enum MouseButton { 192 enum MouseButton {
208 kLeft = 0, 193 kLeft = 0,
209 kRight = 1, 194 kRight = 1,
210 }; 195 };
211 196
212 // This object freezes repainting of the edit until the object is destroyed. 197 // 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 198 // 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 199 // don't freeze, the user will see a rapid series of calls to these as
215 // flickers. 200 // flickers.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 // clipped to be within the horizontal bounds of the visible text. 312 // clipped to be within the horizontal bounds of the visible text.
328 // 313 //
329 // This is used in our mouse handlers to work around quirky behaviors of the 314 // 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 315 // underlying CRichEditCtrl like not supporting triple-click when the user
331 // doesn't click on the text itself. 316 // doesn't click on the text itself.
332 // 317 //
333 // |is_triple_click| should be true iff this is the third click of a triple 318 // |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. 319 // click. Sadly, we need to clip slightly differently in this case.
335 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const; 320 LONG ClipXCoordToVisibleText(LONG x, bool is_triple_click) const;
336 321
322 virtual int GetOmniboxTextLength() OVERRIDE;
323
337 // Parses the contents of the control for the scheme and the host name. 324 // 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. 325 // Highlights the scheme in green or red depending on it security level.
339 // If a host name is found, it makes it visually stronger. 326 // If a host name is found, it makes it visually stronger.
340 void EmphasizeURLComponents(); 327 virtual void EmphasizeURLComponents() OVERRIDE;
341 328
342 // Erases the portion of the selection in the font's y-adjustment area. For 329 // 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 330 // some reason the edit draws the selection rect here even though it's not
344 // part of the font. 331 // part of the font.
345 void EraseTopOfSelection(CDC* dc, 332 void EraseTopOfSelection(CDC* dc,
346 const CRect& client_rect, 333 const CRect& client_rect,
347 const CRect& paint_clip_rect); 334 const CRect& paint_clip_rect);
348 335
349 // Draws a slash across the scheme if desired. 336 // Draws a slash across the scheme if desired.
350 void DrawSlashForInsecureScheme(HDC hdc, 337 void DrawSlashForInsecureScheme(HDC hdc,
351 const CRect& client_rect, 338 const CRect& client_rect,
352 const CRect& paint_clip_rect); 339 const CRect& paint_clip_rect);
353 340
354 // Renders the drop highlight. 341 // Renders the drop highlight.
355 void DrawDropHighlight(HDC hdc, 342 void DrawDropHighlight(HDC hdc,
356 const CRect& client_rect, 343 const CRect& client_rect,
357 const CRect& paint_clip_rect); 344 const CRect& paint_clip_rect);
358 345
359 // Internally invoked whenever the text changes in some way. 346 // Internally invoked whenever the text changes in some way.
360 void TextChanged(); 347 void TextChanged() OVERRIDE;
361 348
362 // Getter for the text_object_model_. Note that the pointer returned here is 349 // 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 350 // only valid as long as the AutocompleteEdit is still alive. Also, if the
364 // underlying call fails, this may return NULL. 351 // underlying call fails, this may return NULL.
365 ITextDocument* GetTextObjectModel() const; 352 ITextDocument* GetTextObjectModel() const;
366 353
367 // Invoked during a mouse move. As necessary starts a drag and drop session. 354 // Invoked during a mouse move. As necessary starts a drag and drop session.
368 void StartDragIfNecessary(const CPoint& point); 355 void StartDragIfNecessary(const CPoint& point);
369 356
370 // Invoked during a mouse down. If the mouse location is over the selection 357 // Invoked during a mouse down. If the mouse location is over the selection
(...skipping 19 matching lines...) Expand all
390 int WidthNeededToDisplay(const string16& text) const; 377 int WidthNeededToDisplay(const string16& text) const;
391 378
392 // Real implementation of OnAfterPossibleChange() method. 379 // Real implementation of OnAfterPossibleChange() method.
393 // If |force_text_changed| is true, then the text_changed code will always be 380 // 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. 381 // triggerred no matter if the text is actually changed or not.
395 bool OnAfterPossibleChangeInternal(bool force_text_changed); 382 bool OnAfterPossibleChangeInternal(bool force_text_changed);
396 383
397 // Common implementation for performing a drop on the edit view. 384 // Common implementation for performing a drop on the edit view.
398 int OnPerformDropImpl(const views::DropTargetEvent& event, bool in_drag); 385 int OnPerformDropImpl(const views::DropTargetEvent& event, bool in_drag);
399 386
400 scoped_ptr<OmniboxEditModel> model_;
401
402 scoped_ptr<OmniboxPopupView> popup_view_; 387 scoped_ptr<OmniboxPopupView> popup_view_;
403 388
404 OmniboxEditController* controller_;
405
406 // The parent view for the edit, used to align the popup and for 389 // The parent view for the edit, used to align the popup and for
407 // accessibility. 390 // accessibility.
408 LocationBarView* parent_view_; 391 LocationBarView* parent_view_;
409 392
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 393 // 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. 394 // different presentation (font size / color). This is used for popups.
418 bool popup_window_mode_; 395 bool popup_window_mode_;
419 396
420 // True if we should prevent attempts to make the window visible when we 397 // True if we should prevent attempts to make the window visible when we
421 // handle WM_WINDOWPOSCHANGING. While toggling fullscreen mode, the main 398 // 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 399 // window is hidden, and if the edit is shown it will draw over the main
423 // window when that window reappears. 400 // window when that window reappears.
424 bool force_hidden_; 401 bool force_hidden_;
425 402
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // Instance of accessibility information and handling. 498 // Instance of accessibility information and handling.
522 mutable base::win::ScopedComPtr<IAccessible> autocomplete_accessibility_; 499 mutable base::win::ScopedComPtr<IAccessible> autocomplete_accessibility_;
523 500
524 // The native view host. 501 // The native view host.
525 views::NativeViewHost* native_view_host_; 502 views::NativeViewHost* native_view_host_;
526 503
527 DISALLOW_COPY_AND_ASSIGN(OmniboxViewWin); 504 DISALLOW_COPY_AND_ASSIGN(OmniboxViewWin);
528 }; 505 };
529 506
530 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_WIN_H_ 507 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_VIEW_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698