summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/panels/taskbar_window_thumbnailer_win.h
blob: 8031599501e71f1c736378a4895dd9d8d609f64e (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
// Copyright (c) 2012 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_UI_VIEWS_PANELS_TASKBAR_WINDOW_THUMBNAILER_WIN_H_
#define CHROME_BROWSER_UI_VIEWS_PANELS_TASKBAR_WINDOW_THUMBNAILER_WIN_H_

#include <vector>
#include "base/memory/scoped_ptr.h"
#include "ui/base/win/hwnd_subclass.h"

class SkBitmap;

class TaskbarWindowThumbnailerDelegateWin {
 public:
  // Returns the list of handles for all windows that are used to construct the
  // thumbnail. If empty list is returned, the snapshot of current window
  // is used.
  virtual std::vector<HWND> GetSnapshotWindowHandles() const = 0;
};

// Provides the custom thumbnail and live preview for the window that appears
// in the taskbar (Windows 7 and later).
class TaskbarWindowThumbnailerWin : public ui::HWNDMessageFilter {
 public:
  TaskbarWindowThumbnailerWin(HWND hwnd,
                              TaskbarWindowThumbnailerDelegateWin* delegate);
  virtual ~TaskbarWindowThumbnailerWin();

  // Starts using the custom snapshot for live preview. The snapshot is only
  // captured once when the system requests it, so the updates of the panels'
  // content will not be automatically reflected in the thumbnail.
  void Start();

  // Stops providing the custom snapshot for live preview.
  void Stop();

  // Captures the snapshot now instead of when the system requests it.
  void CaptureSnapshot();

  // Invalidates the snapshot such that a fresh copy can be obtained next time
  // when the system requests it.
  void InvalidateSnapshot();

  // Provide the snapshot to the new window. If the snapshot is captured for the
  // old window, it will also be used for the new window.
  void ReplaceWindow(HWND new_hwnd);

 private:
  // Overridden from ui::HWNDMessageFilter:
  virtual bool FilterMessage(HWND hwnd,
                             UINT message,
                             WPARAM w_param,
                             LPARAM l_param,
                             LRESULT* l_result) OVERRIDE;

  // Message handlers.
  bool OnDwmSendIconicThumbnail(int width, int height, LRESULT* l_result);
  bool OnDwmSendIconicLivePreviewBitmap(LRESULT* l_result);

  // Captures and returns the screenshot of the window. The caller is
  // responsible to release the returned SkBitmap instance.
  SkBitmap* CaptureWindowImage() const;

  HWND hwnd_;
  TaskbarWindowThumbnailerDelegateWin* delegate_;  // Weak, owns us.
  scoped_ptr<SkBitmap> capture_bitmap_;

  DISALLOW_COPY_AND_ASSIGN(TaskbarWindowThumbnailerWin);
};

#endif  // CHROME_BROWSER_UI_VIEWS_PANELS_TASKBAR_WINDOW_THUMBNAILER_WIN_H_