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

Side by Side Diff: chrome/browser/tab_contents/match_preview.h

Issue 3332022: Bunch of match preview tweaks: (Closed)
Patch Set: Add string16 include Created 10 years, 3 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_TAB_CONTENTS_MATCH_PREVIEW_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_
7 #pragma once
7 8
8 #include "base/basictypes.h" 9 #include "base/basictypes.h"
9 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/string16.h"
12 #include "base/timer.h"
13 #include "chrome/browser/search_engines/template_url_id.h"
14 #include "chrome/common/page_transition_types.h"
10 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
11 16
17 struct AutocompleteMatch;
18 class MatchPreviewDelegate;
12 class TabContents; 19 class TabContents;
13 20
14 // MatchPreview maintains a TabContents that is intended to give a preview of 21 // MatchPreview maintains a TabContents that is intended to give a preview of
15 // a URL. MatchPreview is owned by TabContents. 22 // a URL. MatchPreview is owned by Browser.
16 //
17 // As the user types in the omnibox the LocationBar updates MatchPreview by
18 // way of 'Update'. If the user does a gesture on the preview, say clicks a
19 // link, the TabContentsDelegate of the hosting TabContents is notified with
20 // CommitMatchPreview and the TabContents maintained by MatchPreview replaces
21 // the current TabContents in the TabStripModel.
22 // 23 //
23 // At any time the TabContents maintained by MatchPreview may be destroyed by 24 // At any time the TabContents maintained by MatchPreview may be destroyed by
24 // way of 'DestroyPreviewContents'. Consumers of MatchPreview can detect the 25 // way of |DestroyPreviewContents|, which results in |HideMatchPreview| being
25 // preview TabContents was destroyed by observing TAB_CONTENTS_DESTROYED. 26 // invoked on the delegate. Similarly the preview may be committed at any time
26 // 27 // by invoking |CommitCurrentPreview|, which results in |CommitMatchPreview|
27 // Consumers of MatchPreview can detect a new TabContents was created by 28 // being invoked on the delegate.
28 // MatchPreview by listening for MATCH_PREVIEW_TAB_CONTENTS_CREATED.
29 class MatchPreview { 29 class MatchPreview {
30 public: 30 public:
31 explicit MatchPreview(TabContents* host); 31 explicit MatchPreview(MatchPreviewDelegate* delegate);
32 ~MatchPreview(); 32 ~MatchPreview();
33 33
34 // Is MatchPreview enabled? 34 // Is MatchPreview enabled?
35 static bool IsEnabled(); 35 static bool IsEnabled();
36 36
37 // Invoked as the user types in the omnibox with the url to navigate to. If 37 // Invoked as the user types in the omnibox with the url to navigate to. If
38 // the url is empty and there is a preview TabContents it is destroyed. If url 38 // the url is empty and there is a preview TabContents it is destroyed. If url
39 // is non-empty and the preview TabContents has not been created it is 39 // is non-empty and the preview TabContents has not been created it is
40 // created. 40 // created.
41 void Update(const GURL& url); 41 void Update(TabContents* tab_contents,
42 const AutocompleteMatch& match,
43 const string16& user_text,
44 string16* suggested_text);
42 45
43 // Destroys the preview TabContents. Does nothing if the preview TabContents 46 // Destroys the preview TabContents. Does nothing if the preview TabContents
44 // has not been created. 47 // has not been created.
45 void DestroyPreviewContents(); 48 void DestroyPreviewContents();
46 49
47 // Invoked when the user does some gesture that should trigger making the 50 // Invoked when the user does some gesture that should trigger making the
48 // current previewed page the permanent page. 51 // current previewed page the permanent page.
49 void CommitCurrentPreview(); 52 void CommitCurrentPreview();
50 53
51 // Releases the preview TabContents passing ownership to the caller. This is 54 // Releases the preview TabContents passing ownership to the caller. This is
52 // intended to be called when the preview TabContents is committed. 55 // intended to be called when the preview TabContents is committed. This does
53 TabContents* ReleasePreviewContents(); 56 // not notify the delegate.
57 TabContents* ReleasePreviewContents(bool commit_history);
54 58
55 // The TabContents we're maintaining the preview for. 59 // TabContents the match is being shown for.
56 TabContents* host() { return host_; } 60 TabContents* tab_contents() const { return tab_contents_; }
57 61
58 // The preview TabContents; may be null. 62 // The preview TabContents; may be null.
59 TabContents* preview_contents() { return preview_contents_.get(); } 63 TabContents* preview_contents() const { return preview_contents_.get(); }
64
65 // Returns true if the preview TabContents is active. In some situations this
66 // may return false yet preview_contents() returns non-NULL.
67 bool is_active() const { return is_active_; }
68
69 const GURL& url() const { return url_; }
60 70
61 private: 71 private:
72 class FrameLoadObserver;
73 class PaintObserverImpl;
62 class TabContentsDelegateImpl; 74 class TabContentsDelegateImpl;
63 75
76 // Invoked when the page wants to update the suggested text. If |user_text_|
77 // starts with |suggested_text|, then the delegate is notified of the change,
78 // which results in updating the omnibox.
79 void SetCompleteSuggestedText(const string16& suggested_text);
80
81 // Invoked when the preview paints. This notifies the delegate the preview is
82 // ready to be shown.
83 void PreviewDidPaint();
84
85 // Invoked once the page has finished loading and the script has been sent.
86 void PageFinishedLoading();
87
88 MatchPreviewDelegate* delegate_;
89
90 // The TabContents last passed to |Update|.
91 TabContents* tab_contents_;
92
64 // The url we're displaying. 93 // The url we're displaying.
65 GURL url_; 94 GURL url_;
66 95
67 // The TabContents we're providing the preview for.
68 TabContents* host_;
69
70 // Delegate of the preview TabContents. Used to detect when the user does some 96 // Delegate of the preview TabContents. Used to detect when the user does some
71 // gesture on the TabContents and the preview needs to be activated. 97 // gesture on the TabContents and the preview needs to be activated.
72 scoped_ptr<TabContentsDelegateImpl> delegate_; 98 scoped_ptr<TabContentsDelegateImpl> preview_tab_contents_delegate_;
73 99
74 // The preview TabContents; may be null. 100 // The preview TabContents; may be null.
75 scoped_ptr<TabContents> preview_contents_; 101 scoped_ptr<TabContents> preview_contents_;
76 102
103 // Has notification been sent out that the preview TabContents is ready to be
104 // shown?
105 bool is_active_;
106
107 // The text the user typed in the omnibox.
108 string16 user_text_;
109
110 // The latest suggestion from the page.
111 string16 complete_suggested_text_;
112
113 // If we're showing instant results this is the ID of the TemplateURL driving
114 // the results. A value of 0 means there is no TemplateURL.
115 TemplateURLID template_url_id_;
116
117 scoped_ptr<FrameLoadObserver> frame_load_observer_;
118
77 DISALLOW_COPY_AND_ASSIGN(MatchPreview); 119 DISALLOW_COPY_AND_ASSIGN(MatchPreview);
78 }; 120 };
79 121
80 #endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_ 122 #endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url.h ('k') | chrome/browser/tab_contents/match_preview.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698