blob: cc6605b70cdcf4124177e76e168ed0e9f6906c0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_
#define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "googleurl/src/gurl.h"
class TabContents;
// MatchPreview maintains a TabContents that is intended to give a preview of
// a URL. MatchPreview is owned by TabContents.
//
// As the user types in the omnibox the LocationBar updates MatchPreview by
// way of 'Update'. If the user does a gesture on the preview, say clicks a
// link, the TabContentsDelegate of the hosting TabContents is notified with
// CommitMatchPreview and the TabContents maintained by MatchPreview replaces
// the current TabContents in the TabStripModel.
//
// At any time the TabContents maintained by MatchPreview may be destroyed by
// way of 'DestroyPreviewContents'. Consumers of MatchPreview can detect the
// preview TabContents was destroyed by observing TAB_CONTENTS_DESTROYED.
//
// Consumers of MatchPreview can detect a new TabContents was created by
// MatchPreview by listening for MATCH_PREVIEW_TAB_CONTENTS_CREATED.
class MatchPreview {
public:
explicit MatchPreview(TabContents* host);
~MatchPreview();
// Is MatchPreview enabled?
static bool IsEnabled();
// Invoked as the user types in the omnibox with the url to navigate to. If
// the url is empty and there is a preview TabContents it is destroyed. If url
// is non-empty and the preview TabContents has not been created it is
// created.
void Update(const GURL& url);
// Destroys the preview TabContents. Does nothing if the preview TabContents
// has not been created.
void DestroyPreviewContents();
// Invoked when the user does some gesture that should trigger making the
// current previewed page the permanent page.
void CommitCurrentPreview();
// Releases the preview TabContents passing ownership to the caller. This is
// intended to be called when the preview TabContents is committed.
TabContents* ReleasePreviewContents();
// The TabContents we're maintaining the preview for.
TabContents* host() { return host_; }
// The preview TabContents; may be null.
TabContents* preview_contents() { return preview_contents_.get(); }
private:
class TabContentsDelegateImpl;
// The url we're displaying.
GURL url_;
// The TabContents we're providing the preview for.
TabContents* host_;
// Delegate of the preview TabContents. Used to detect when the user does some
// gesture on the TabContents and the preview needs to be activated.
scoped_ptr<TabContentsDelegateImpl> delegate_;
// The preview TabContents; may be null.
scoped_ptr<TabContents> preview_contents_;
DISALLOW_COPY_AND_ASSIGN(MatchPreview);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_
|