diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-18 21:22:51 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-18 21:22:51 +0000 |
commit | 434ff6a6e51ac0c1853c6b0ade3af6cfea8092de (patch) | |
tree | c0fc0a599d9f38d0b98ed994e533c8b38d21ce2e /chrome/browser/views/tabs | |
parent | 39797c02ac4020c0537166b3311a57e6d0c296ac (diff) | |
download | chromium_src-434ff6a6e51ac0c1853c6b0ade3af6cfea8092de.zip chromium_src-434ff6a6e51ac0c1853c6b0ade3af6cfea8092de.tar.gz chromium_src-434ff6a6e51ac0c1853c6b0ade3af6cfea8092de.tar.bz2 |
Refactors HWNDPhotobooth into NativeViewPhotobooth and
NativeViewPhotoboothWin.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/115475
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16324 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/tabs')
-rw-r--r-- | chrome/browser/views/tabs/dragged_tab_controller.cc | 8 | ||||
-rw-r--r-- | chrome/browser/views/tabs/dragged_tab_controller.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/tabs/dragged_tab_view.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/tabs/dragged_tab_view.h | 6 | ||||
-rw-r--r-- | chrome/browser/views/tabs/native_view_photobooth.h | 43 | ||||
-rw-r--r-- | chrome/browser/views/tabs/native_view_photobooth_win.cc (renamed from chrome/browser/views/tabs/hwnd_photobooth.cc) | 31 | ||||
-rw-r--r-- | chrome/browser/views/tabs/native_view_photobooth_win.h (renamed from chrome/browser/views/tabs/hwnd_photobooth.h) | 30 |
7 files changed, 86 insertions, 40 deletions
diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc index 7f37ac4..4790878 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.cc +++ b/chrome/browser/views/tabs/dragged_tab_controller.cc @@ -16,7 +16,7 @@ #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/views/frame/browser_view.h" #include "chrome/browser/views/tabs/dragged_tab_view.h" -#include "chrome/browser/views/tabs/hwnd_photobooth.h" +#include "chrome/browser/views/tabs/native_view_photobooth.h" #include "chrome/browser/views/tabs/tab.h" #include "chrome/browser/views/tabs/tab_strip.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -761,8 +761,10 @@ void DraggedTabController::Detach() { // Set up the photo booth to start capturing the contents of the dragged // TabContents. - if (!photobooth_.get()) - photobooth_.reset(new HWNDPhotobooth(dragged_contents_->GetNativeView())); + if (!photobooth_.get()) { + photobooth_.reset( + NativeViewPhotobooth::Create(dragged_contents_->GetNativeView())); + } // Update the View. This NULL check is necessary apparently in some // conditions during automation where the view_ is destroyed inside a diff --git a/chrome/browser/views/tabs/dragged_tab_controller.h b/chrome/browser/views/tabs/dragged_tab_controller.h index 2418913..3512650 100644 --- a/chrome/browser/views/tabs/dragged_tab_controller.h +++ b/chrome/browser/views/tabs/dragged_tab_controller.h @@ -20,7 +20,7 @@ class View; } class BrowserWindow; class DraggedTabView; -class HWNDPhotobooth; +class NativeViewPhotobooth; class SkBitmap; class Tab; class TabStrip; @@ -258,7 +258,7 @@ class DraggedTabController : public TabContentsDelegate, // The photo-booth the TabContents sits in when the Tab is detached, to // obtain screen shots. - scoped_ptr<HWNDPhotobooth> photobooth_; + scoped_ptr<NativeViewPhotobooth> photobooth_; // The position of the mouse (in screen coordinates) at the start of the drag // operation. This is used to calculate minimum elasticity before a diff --git a/chrome/browser/views/tabs/dragged_tab_view.cc b/chrome/browser/views/tabs/dragged_tab_view.cc index 87b96c45..2c5d7dd 100644 --- a/chrome/browser/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/views/tabs/dragged_tab_view.cc @@ -7,7 +7,7 @@ #include "app/gfx/canvas.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tabs/tab_strip_model.h" -#include "chrome/browser/views/tabs/hwnd_photobooth.h" +#include "chrome/browser/views/tabs/native_view_photobooth.h" #include "chrome/browser/views/tabs/tab_renderer.h" #include "third_party/skia/include/core/SkShader.h" #include "views/widget/widget_win.h" @@ -94,7 +94,7 @@ void DraggedTabView::Attach(int selected_width) { Update(); } -void DraggedTabView::Detach(HWNDPhotobooth* photobooth) { +void DraggedTabView::Detach(NativeViewPhotobooth* photobooth) { attached_ = false; photobooth_ = photobooth; container_->SetLayeredAlpha(kTransparentAlpha); diff --git a/chrome/browser/views/tabs/dragged_tab_view.h b/chrome/browser/views/tabs/dragged_tab_view.h index 504681b..839dc07 100644 --- a/chrome/browser/views/tabs/dragged_tab_view.h +++ b/chrome/browser/views/tabs/dragged_tab_view.h @@ -18,7 +18,7 @@ class WidgetWin; namespace gfx { class Point; } -class HWNDPhotobooth; +class NativeViewPhotobooth; class Tab; class TabContents; class TabRenderer; @@ -39,7 +39,7 @@ class DraggedTabView : public views::View, void Attach(int selected_width); // Notifies the DraggedTabView that it has been detached from a TabStrip. - void Detach(HWNDPhotobooth* photobooth); + void Detach(NativeViewPhotobooth* photobooth); // Notifies the DraggedTabView that it should update itself. void Update(); @@ -103,7 +103,7 @@ class DraggedTabView : public views::View, // A handle to the DIB containing the current screenshot of the TabContents // we are dragging. - HWNDPhotobooth* photobooth_; + NativeViewPhotobooth* photobooth_; // The dimensions of the TabContents being dragged. gfx::Size contents_size_; diff --git a/chrome/browser/views/tabs/native_view_photobooth.h b/chrome/browser/views/tabs/native_view_photobooth.h new file mode 100644 index 0000000..3d639b3 --- /dev/null +++ b/chrome/browser/views/tabs/native_view_photobooth.h @@ -0,0 +1,43 @@ +// Copyright (c) 2006-2008 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_VIEWS_TABS_NATIVE_VIEW_PHOTOBOOTH_H_ +#define CHROME_BROWSER_VIEWS_TABS_NATIVE_VIEW_PHOTOBOOTH_H_ + +#include "base/gfx/native_widget_types.h" + +namespace gfx { +class Canvas; +class Rect; +} +/////////////////////////////////////////////////////////////////////////////// +// NativeViewPhotobooth +// +// An object that a NativeView "steps into" to have its picture taken. This is +// used to generate a full size screen shot of the contents of a NativeView +// including any child windows. +// +// Implementation note: This causes the NativeView to be re-parented to a +// mostly off-screen layered window. +// +class NativeViewPhotobooth { + public: + // Creates the photo booth. Constructs a nearly off-screen window, parents + // the view, then shows it. The caller is responsible for destroying this + // photo-booth, since the photo-booth will detach it before it is destroyed. + static NativeViewPhotobooth* Create(gfx::NativeView initial_view); + + // Destroys the photo booth window. + virtual ~NativeViewPhotobooth() {} + + // Replaces the view in the photo booth with the specified one. + virtual void Replace(gfx::NativeView new_view) = 0; + + // Paints the current display image of the window into |canvas|, clipped to + // |target_bounds|. + virtual void PaintScreenshotIntoCanvas(gfx::Canvas* canvas, + const gfx::Rect& target_bounds) = 0; +}; + +#endif // #ifndef CHROME_BROWSER_VIEWS_TABS_NATIVE_VIEW_PHOTOBOOTH_H_ diff --git a/chrome/browser/views/tabs/hwnd_photobooth.cc b/chrome/browser/views/tabs/native_view_photobooth_win.cc index c51473c..430e009 100644 --- a/chrome/browser/views/tabs/hwnd_photobooth.cc +++ b/chrome/browser/views/tabs/native_view_photobooth_win.cc @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/views/tabs/native_view_photobooth_win.h" + #include "app/gfx/canvas.h" #include "base/gfx/point.h" #include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/views/tabs/hwnd_photobooth.h" #include "third_party/skia/include/core/SkBitmap.h" #include "views/widget/widget_win.h" @@ -38,23 +39,29 @@ gfx::Point GetCaptureWindowPosition() { } /////////////////////////////////////////////////////////////////////////////// -// HWNDPhotobooth, public: +// NativeViewPhotoboothWin, public: + +// static +NativeViewPhotobooth* NativeViewPhotobooth::Create( + gfx::NativeView initial_view) { + return new NativeViewPhotoboothWin(initial_view); +} -HWNDPhotobooth::HWNDPhotobooth(HWND initial_hwnd) +NativeViewPhotoboothWin::NativeViewPhotoboothWin(HWND initial_hwnd) : capture_window_(NULL), current_hwnd_(initial_hwnd) { DCHECK(IsWindow(current_hwnd_)); CreateCaptureWindow(initial_hwnd); } -HWNDPhotobooth::~HWNDPhotobooth() { +NativeViewPhotoboothWin::~NativeViewPhotoboothWin() { // Detach the attached HWND. The creator of the photo-booth is responsible // for destroying it. - ReplaceHWND(NULL); + Replace(NULL); capture_window_->Close(); } -void HWNDPhotobooth::ReplaceHWND(HWND new_hwnd) { +void NativeViewPhotoboothWin::Replace(HWND new_hwnd) { if (IsWindow(current_hwnd_) && GetParent(current_hwnd_) == capture_window_->GetNativeView()) { // We need to hide the window too, so it doesn't show up in the TaskBar or @@ -77,14 +84,14 @@ void HWNDPhotobooth::ReplaceHWND(HWND new_hwnd) { } } -void HWNDPhotobooth::PaintScreenshotIntoCanvas( +void NativeViewPhotoboothWin::PaintScreenshotIntoCanvas( gfx::Canvas* canvas, const gfx::Rect& target_bounds) { // Our contained window may have been re-parented. Make sure it belongs to - // us until someone calls ReplaceHWND(NULL). + // us until someone calls Replace(NULL). if (IsWindow(current_hwnd_) && GetParent(current_hwnd_) != capture_window_->GetNativeView()) { - ReplaceHWND(current_hwnd_); + Replace(current_hwnd_); } // We compel the contained HWND to paint now, synchronously. We do this to @@ -111,9 +118,9 @@ void HWNDPhotobooth::PaintScreenshotIntoCanvas( } /////////////////////////////////////////////////////////////////////////////// -// HWNDPhotobooth, private: +// NativeViewPhotoboothWin, private: -void HWNDPhotobooth::CreateCaptureWindow(HWND initial_hwnd) { +void NativeViewPhotoboothWin::CreateCaptureWindow(HWND initial_hwnd) { // Snapshotting a HWND is tricky - if the HWND is clipped (e.g. positioned // partially off-screen) then just blitting from the HWND' DC to the capture // bitmap would be incorrect, since the capture bitmap would show only the @@ -155,5 +162,5 @@ void HWNDPhotobooth::CreateCaptureWindow(HWND initial_hwnd) { SetLayeredWindowAttributes( capture_window_->GetNativeView(), RGB(0xFF, 0xFF, 0xFF), 0xFF, LWA_ALPHA); - ReplaceHWND(initial_hwnd); + Replace(initial_hwnd); } diff --git a/chrome/browser/views/tabs/hwnd_photobooth.h b/chrome/browser/views/tabs/native_view_photobooth_win.h index c3ef430..6429380 100644 --- a/chrome/browser/views/tabs/hwnd_photobooth.h +++ b/chrome/browser/views/tabs/native_view_photobooth_win.h @@ -2,15 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_VIEWS_TABS_HWND_PHOTOBOOTH_H__ -#define CHROME_BROWSER_VIEWS_TABS_HWND_PHOTOBOOTH_H__ +#ifndef CHROME_BROWSER_VIEWS_TABS_NATIVE_VIEW_PHOTOBOOTH_WIN_H_ +#define CHROME_BROWSER_VIEWS_TABS_NATIVE_VIEW_PHOTOBOOTH_WIN_H_ -#include "base/basictypes.h" -#include "base/gfx/rect.h" +#include "chrome/browser/views/tabs/native_view_photobooth.h" -namespace gfx { -class Canvas; -} namespace views { class WidgetWin; } @@ -25,27 +21,25 @@ class WidgetWin; // Implementation note: This causes the HWND to be re-parented to a mostly // off-screen layered window. // -class HWNDPhotobooth { +class NativeViewPhotoboothWin : public NativeViewPhotobooth { public: // Creates the photo booth. Constructs a nearly off-screen window, parents // the HWND, then shows it. The caller is responsible for destroying this // window, since the photo-booth will detach it before it is destroyed. // |canvas| is a canvas to paint the contents into, and dest_bounds is the // target area in |canvas| to which painted contents will be clipped. - explicit HWNDPhotobooth(HWND initial_hwnd); + explicit NativeViewPhotoboothWin(gfx::NativeView initial_view); // Destroys the photo booth window. - virtual ~HWNDPhotobooth(); + virtual ~NativeViewPhotoboothWin(); - // Replaces the HWND in the photo booth with the specified one. The caller is - // responsible for destroying this HWND since it will be detached from the - // capture window before the capture window is destroyed. - void ReplaceHWND(HWND new_hwnd); + // Replaces the view in the photo booth with the specified one. + virtual void Replace(gfx::NativeView new_view); // Paints the current display image of the window into |canvas|, clipped to // |target_bounds|. - void PaintScreenshotIntoCanvas(gfx::Canvas* canvas, - const gfx::Rect& target_bounds); + virtual void PaintScreenshotIntoCanvas(gfx::Canvas* canvas, + const gfx::Rect& target_bounds); private: // Creates a mostly off-screen window to contain the HWND to be captured. @@ -57,7 +51,7 @@ class HWNDPhotobooth { // The current HWND being captured. HWND current_hwnd_; - DISALLOW_EVIL_CONSTRUCTORS(HWNDPhotobooth); + DISALLOW_COPY_AND_ASSIGN(NativeViewPhotoboothWin); }; -#endif // #ifndef CHROME_BROWSER_VIEWS_TABS_HWND_PHOTOBOOTH_H__ +#endif // #ifndef CHROME_BROWSER_VIEWS_TABS_NATIVE_VIEW_PHOTOBOOTH_WIN_H_ |