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

Side by Side Diff: chrome/browser/aeropeek_manager.h

Issue 303033: Implements AeroPeek of Windows 7.. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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
« no previous file with comments | « base/scoped_native_library_unittest.cc ('k') | chrome/browser/aeropeek_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_AEROPEEK_MANAGER_H_
6 #define CHROME_BROWSER_AEROPEEK_MANAGER_H_
7
8 #include <list>
9
10 #include "app/gfx/insets.h"
11 #include "base/waitable_event.h"
12 #include "chrome/browser/tabs/tab_strip_model.h"
13
14 namespace gfx {
15 class Size;
16 }
17 class TabContents;
18 class AeroPeekWindow;
19 class SkBitmap;
20
21 // A class which defines interfaces called from AeroPeekWindow.
22 // This class is used for dispatching an event received by a thumbnail window
23 // and for retrieving information from Chrome.
24 // An AeroPeek window receives the following events:
25 // * A user clicks an AeroPeek thumbnail.
26 // We need to select a tab associated with this window.
27 // * A user closes an AeroPeek thumbnail.
28 // We need to close a tab associated with this window.
29 // * A user clicks a toolbar button in an AeroPeek window.
30 // We may need to dispatch this button event to a tab associated with this
31 // thumbnail window.
32 // <http://msdn.microsoft.com/en-us/library/dd378460(VS.85).aspx#thumbbars>.
33 // Also, it needs the following information of the browser:
34 // * The bitmap of a tab associated with this window.
35 // This bitmap is used for creating thumbnail and preview images.
36 // * The rectangle of a browser frame.
37 // This rectangle is used for pasting the above bitmap to the right position
38 // and for marking the tab-content area as opaque.
39 // We assume these functions are called only from a UI thread (i.e.
40 // Chrome_BrowserMain).
41 class AeroPeekWindowDelegate {
42 public:
43 virtual void ActivateTab(int tab_id) = 0;
44 virtual void CloseTab(int tab_id) = 0;
45 virtual void GetContentInsets(gfx::Insets* insets) = 0;
46 virtual bool GetTabThumbnail(int tab_id, SkBitmap* thumbnail) = 0;
47 virtual bool GetTabPreview(int tab_id, SkBitmap* preview) = 0;
48 };
49
50 // A class that implements AeroPeek of Windows 7:
51 // <http://msdn.microsoft.com/en-us/library/dd378460(VS.85).aspx#thumbnails>.
52 // Windows 7 can dispay a thumbnail image of each tab to its taskbar so that
53 // a user can preview the contents of a tab (AeroPeek), choose a tab, close
54 // a tab, etc.
55 // This class implements the TabStripModelObserver interface to receive the
56 // following events sent from TabStripModel and dispatch them to Windows:
57 // * A tab is added.
58 // This class adds a thumbnail window for this tab to the thumbnail list
59 // of Windows.
60 // * A tab is being closed.
61 // This class deletes the thumbnail window associated with this tab from the
62 // thumbnail list of Windows.
63 // * A tab has been updated.
64 // This class updates the image of the thumbnail window associated with this
65 // tab.
66 // Also, this class receives events sent from Windows via thumbnail windows to
67 // TabStripModel:
68 // * A thumbnail window is closed.
69 // Ask TabStrip to close the tab associated with this thumbnail window.
70 // * A thumbnail window is selected.
71 // Ask TabStrip to activate the tab associated with this thumbnail window.
72 //
73 // The simplest usage of this class is:
74 // 1. Create an instance of TabThumbnailManager.
75 // 2. Add this instance to the observer list of a TabStrip object.
76 //
77 // scoped_ptr<TabThumbnailManager> manager;
78 // manager.reset(new TabThumbnailManager(
79 // frame_->GetWindow()->GetNativeWindow(),
80 // border_left,
81 // border_top,
82 // toolbar_top));
83 // g_browser->tabstrip_model()->AddObserver(manager);
84 //
85 // 3. Remove this instance from the observer list of the TabStrip object when
86 // we don't need it.
87 //
88 // g_browser->tabstrip_model()->RemoveObserver(manager);
89 //
90 class AeroPeekManager : public TabStripModelObserver,
91 public AeroPeekWindowDelegate {
92 public:
93 explicit AeroPeekManager(HWND application_window);
94 ~AeroPeekManager();
95
96 // Sets the margins of the "user-perceived content area".
97 // (See comments of |content_insets_|).
98 void SetContentInsets(const gfx::Insets& insets);
99
100 // Returns whether or not we should enable Tab Thumbnailing and Aero Peek
101 // of Windows 7.
102 static bool Enabled();
103
104 // Overridden from TabStripModelObserver:
105 virtual void TabInsertedAt(TabContents* contents,
106 int index,
107 bool foreground);
108 virtual void TabClosingAt(TabContents* contents, int index);
109 virtual void TabDetachedAt(TabContents* contents, int index);
110 virtual void TabSelectedAt(TabContents* old_contents,
111 TabContents* new_contents,
112 int index,
113 bool user_gesture);
114 virtual void TabMoved(TabContents* contents,
115 int from_index,
116 int to_index,
117 bool pinned_state_changed);
118 virtual void TabChangedAt(TabContents* contents,
119 int index,
120 TabChangeType change_type);
121
122 // Overriden from TabThumbnailWindowDelegate:
123 virtual void CloseTab(int tab_id);
124 virtual void ActivateTab(int tab_id);
125 virtual void GetContentInsets(gfx::Insets* insets);
126 virtual bool GetTabThumbnail(int tab_id, SkBitmap* thumbnail);
127 virtual bool GetTabPreview(int tab_id, SkBitmap* preview);
128
129 private:
130 // Deletes the TabThumbnailWindow object associated with the specified
131 // Tab ID.
132 void DeleteAeroPeekWindow(int tab_id);
133
134 // Retrieves the AeroPeekWindow object associated with the specified
135 // Tab ID.
136 AeroPeekWindow* GetAeroPeekWindow(int tab_id) const;
137
138 // Returns a rectangle that fits into the destination rectangle and keeps
139 // the pixel-aspect ratio of the source one.
140 // (This function currently uses the longer-fit algorithm as IE8 does.)
141 void GetOutputBitmapSize(const gfx::Size& destination,
142 const gfx::Size& source,
143 gfx::Size* output) const;
144
145 // Returns the TabContents object associated with the specified Tab ID only
146 // if it is alive.
147 // Since Windows cannot send AeroPeek events directly to Chrome windows, we
148 // use a place-holder window to receive AeroPeek events. So, when Windows
149 // sends an AeroPeek event, the corresponding tab (and TabContents) may have
150 // been deleted by Chrome. To prevent us from accessing deleted TabContents,
151 // we need to check if the tab is still alive.
152 TabContents* GetTabContents(int tab_id) const;
153
154 // Returns the tab ID from the specified TabContents.
155 int GetTabID(TabContents* contents) const;
156
157 private:
158 // The parent window of the place-holder windows used by AeroPeek.
159 // In the case of Chrome, this window becomes a browser frame.
160 HWND application_window_;
161
162 // The list of the place-holder windows used by AeroPeek.
163 std::list<AeroPeekWindow*> tab_list_;
164
165 // The left and top borders of the frame window.
166 // When we create a preview bitmap, we use these values for preventing from
167 // over-writing the area of the browser frame.
168 int border_left_;
169 int border_top_;
170
171 // The top position of the toolbar.
172 // This value is used for setting the alpha values of the frame area so a
173 // preview image can use transparent colors only in the frame area.
174 int toolbar_top_;
175
176 // The margins of the "user-perceived content area".
177 // This value is used for pasting a tab image onto this "user-perceived
178 // content area" when creating a preview image.
179 gfx::Insets content_insets_;
180 };
181
182 #endif // CHROME_BROWSER_AEROPEEK_MANAGER_H_
OLDNEW
« no previous file with comments | « base/scoped_native_library_unittest.cc ('k') | chrome/browser/aeropeek_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698