summaryrefslogtreecommitdiff
path: root/widget/windows/TaskbarPreview.h
blob: d5f6b86f1940003488313459d459bcdf80202760 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* vim: se cin sw=2 ts=2 et : */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __mozilla_widget_TaskbarPreview_h__
#define __mozilla_widget_TaskbarPreview_h__

#include <windows.h>
#include <shobjidl.h>
#undef LogSeverity // SetupAPI.h #defines this as DWORD

#include "mozilla/RefPtr.h"
#include <nsITaskbarPreview.h>
#include <nsITaskbarPreviewController.h>
#include <nsString.h>
#include <nsWeakPtr.h>
#include <nsIDocShell.h>
#include "WindowHook.h"

namespace mozilla {
namespace widget {

class TaskbarPreviewCallback;

class TaskbarPreview : public nsITaskbarPreview
{
public:
  TaskbarPreview(ITaskbarList4 *aTaskbar, nsITaskbarPreviewController *aController, HWND aHWND, nsIDocShell *aShell);

  friend class TaskbarPreviewCallback;

  NS_DECL_NSITASKBARPREVIEW

protected:
  virtual ~TaskbarPreview();

  // Called to update ITaskbarList4 dependent properties
  virtual nsresult UpdateTaskbarProperties();

  // Invoked when the preview is made visible
  virtual nsresult Enable();
  // Invoked when the preview is made invisible
  virtual nsresult Disable();

  // Detaches this preview from the nsWindow instance it's tied to
  virtual void DetachFromNSWindow();

  // Determines if the window is available and a destroy has not yet started
  bool IsWindowAvailable() const;

  // Marks this preview as being active
  virtual nsresult ShowActive(bool active) = 0;
  // Gets a reference to the window used to handle the preview messages
  virtual HWND& PreviewWindow() = 0;

  // Window procedure for the PreviewWindow (hooked for window previews)
  virtual LRESULT WndProc(UINT nMsg, WPARAM wParam, LPARAM lParam);

  // Returns whether or not the taskbar icon has been created for mWnd The
  // ITaskbarList4 API requires that we wait until the icon has been created
  // before we can call its methods.
  bool CanMakeTaskbarCalls();

  // Gets the WindowHook for the nsWindow
  WindowHook &GetWindowHook();

  // Enables/disables custom drawing for the given window
  static void EnableCustomDrawing(HWND aHWND, bool aEnable);

  // MSCOM Taskbar interface
  RefPtr<ITaskbarList4> mTaskbar;
  // Controller for this preview
  nsCOMPtr<nsITaskbarPreviewController> mController;
  // The HWND to the nsWindow that this object previews
  HWND                    mWnd;
  // Whether or not this preview is visible
  bool                    mVisible;

private:
  // Called when the tooltip should be updated
  nsresult UpdateTooltip();

  // Requests the controller to draw into a canvas of the given width and
  // height. The resulting bitmap is sent to the DWM to display.
  void DrawBitmap(uint32_t width, uint32_t height, bool isPreview);

  // WindowHook procedure for hooking mWnd
  static bool MainWindowHook(void *aContext,
                               HWND hWnd, UINT nMsg,
                               WPARAM wParam, LPARAM lParam,
                               LRESULT *aResult);

  // Docshell corresponding to the <window> the nsWindow contains
  nsWeakPtr               mDocShell;
  nsString                mTooltip;

  // The preview currently marked as active in the taskbar. nullptr if no
  // preview is active (some other window is).
  static TaskbarPreview  *sActivePreview;
};

/*
 * Callback object TaskbarPreview hands to preview controllers when we
 * request async thumbnail or live preview images. Controllers invoke
 * this interface once they have aquired the requested image.
 */
class TaskbarPreviewCallback : public nsITaskbarPreviewCallback
{
public:
  TaskbarPreviewCallback() :
    mIsThumbnail(true) {
  }

  NS_DECL_ISUPPORTS
  NS_DECL_NSITASKBARPREVIEWCALLBACK

  void SetPreview(TaskbarPreview* aPreview) {
    mPreview = aPreview;
  }

  void SetIsPreview() {
    mIsThumbnail = false;
  }

protected:
  virtual ~TaskbarPreviewCallback() {}

private:
  RefPtr<TaskbarPreview> mPreview;
  bool mIsThumbnail;
};

} // namespace widget
} // namespace mozilla

#endif /* __mozilla_widget_TaskbarPreview_h__ */