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