widget/windows/TaskbarPreviewButton.cpp

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* vim: se cin sw=2 ts=2 et : */
michael@0 2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 3 *
michael@0 4 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #include <windows.h>
michael@0 9 #include <strsafe.h>
michael@0 10
michael@0 11 #include "TaskbarWindowPreview.h"
michael@0 12 #include "TaskbarPreviewButton.h"
michael@0 13 #include "nsWindowGfx.h"
michael@0 14 #include <imgIContainer.h>
michael@0 15
michael@0 16 namespace mozilla {
michael@0 17 namespace widget {
michael@0 18
michael@0 19 NS_IMPL_ISUPPORTS(TaskbarPreviewButton, nsITaskbarPreviewButton, nsISupportsWeakReference)
michael@0 20
michael@0 21 TaskbarPreviewButton::TaskbarPreviewButton(TaskbarWindowPreview* preview, uint32_t index)
michael@0 22 : mPreview(preview), mIndex(index)
michael@0 23 {
michael@0 24 }
michael@0 25
michael@0 26 TaskbarPreviewButton::~TaskbarPreviewButton() {
michael@0 27 SetVisible(false);
michael@0 28 }
michael@0 29
michael@0 30 NS_IMETHODIMP
michael@0 31 TaskbarPreviewButton::GetTooltip(nsAString &aTooltip) {
michael@0 32 aTooltip = mTooltip;
michael@0 33 return NS_OK;
michael@0 34 }
michael@0 35
michael@0 36 NS_IMETHODIMP
michael@0 37 TaskbarPreviewButton::SetTooltip(const nsAString &aTooltip) {
michael@0 38 mTooltip = aTooltip;
michael@0 39 size_t destLength = sizeof Button().szTip / (sizeof Button().szTip[0]);
michael@0 40 wchar_t *tooltip = &(Button().szTip[0]);
michael@0 41 StringCchCopyNW(tooltip,
michael@0 42 destLength,
michael@0 43 mTooltip.get(),
michael@0 44 mTooltip.Length());
michael@0 45 return Update();
michael@0 46 }
michael@0 47
michael@0 48 NS_IMETHODIMP
michael@0 49 TaskbarPreviewButton::GetDismissOnClick(bool *dismiss) {
michael@0 50 *dismiss = (Button().dwFlags & THBF_DISMISSONCLICK) == THBF_DISMISSONCLICK;
michael@0 51 return NS_OK;
michael@0 52 }
michael@0 53
michael@0 54 NS_IMETHODIMP
michael@0 55 TaskbarPreviewButton::SetDismissOnClick(bool dismiss) {
michael@0 56 if (dismiss)
michael@0 57 Button().dwFlags |= THBF_DISMISSONCLICK;
michael@0 58 else
michael@0 59 Button().dwFlags &= ~THBF_DISMISSONCLICK;
michael@0 60 return Update();
michael@0 61 }
michael@0 62
michael@0 63 NS_IMETHODIMP
michael@0 64 TaskbarPreviewButton::GetHasBorder(bool *hasBorder) {
michael@0 65 *hasBorder = (Button().dwFlags & THBF_NOBACKGROUND) != THBF_NOBACKGROUND;
michael@0 66 return NS_OK;
michael@0 67 }
michael@0 68
michael@0 69 NS_IMETHODIMP
michael@0 70 TaskbarPreviewButton::SetHasBorder(bool hasBorder) {
michael@0 71 if (hasBorder)
michael@0 72 Button().dwFlags &= ~THBF_NOBACKGROUND;
michael@0 73 else
michael@0 74 Button().dwFlags |= THBF_NOBACKGROUND;
michael@0 75 return Update();
michael@0 76 }
michael@0 77
michael@0 78 NS_IMETHODIMP
michael@0 79 TaskbarPreviewButton::GetDisabled(bool *disabled) {
michael@0 80 *disabled = (Button().dwFlags & THBF_DISABLED) == THBF_DISABLED;
michael@0 81 return NS_OK;
michael@0 82 }
michael@0 83
michael@0 84 NS_IMETHODIMP
michael@0 85 TaskbarPreviewButton::SetDisabled(bool disabled) {
michael@0 86 if (disabled)
michael@0 87 Button().dwFlags |= THBF_DISABLED;
michael@0 88 else
michael@0 89 Button().dwFlags &= ~THBF_DISABLED;
michael@0 90 return Update();
michael@0 91 }
michael@0 92
michael@0 93 NS_IMETHODIMP
michael@0 94 TaskbarPreviewButton::GetImage(imgIContainer **img) {
michael@0 95 if (mImage)
michael@0 96 NS_ADDREF(*img = mImage);
michael@0 97 else
michael@0 98 *img = nullptr;
michael@0 99 return NS_OK;
michael@0 100 }
michael@0 101
michael@0 102 NS_IMETHODIMP
michael@0 103 TaskbarPreviewButton::SetImage(imgIContainer *img) {
michael@0 104 if (Button().hIcon)
michael@0 105 ::DestroyIcon(Button().hIcon);
michael@0 106 if (img) {
michael@0 107 nsresult rv;
michael@0 108 rv = nsWindowGfx::CreateIcon(img, false, 0, 0,
michael@0 109 nsWindowGfx::GetIconMetrics(nsWindowGfx::kRegularIcon),
michael@0 110 &Button().hIcon);
michael@0 111 NS_ENSURE_SUCCESS(rv, rv);
michael@0 112 } else {
michael@0 113 Button().hIcon = nullptr;
michael@0 114 }
michael@0 115 return Update();
michael@0 116 }
michael@0 117
michael@0 118 NS_IMETHODIMP
michael@0 119 TaskbarPreviewButton::GetVisible(bool *visible) {
michael@0 120 *visible = (Button().dwFlags & THBF_HIDDEN) != THBF_HIDDEN;
michael@0 121 return NS_OK;
michael@0 122 }
michael@0 123
michael@0 124 NS_IMETHODIMP
michael@0 125 TaskbarPreviewButton::SetVisible(bool visible) {
michael@0 126 if (visible)
michael@0 127 Button().dwFlags &= ~THBF_HIDDEN;
michael@0 128 else
michael@0 129 Button().dwFlags |= THBF_HIDDEN;
michael@0 130 return Update();
michael@0 131 }
michael@0 132
michael@0 133 THUMBBUTTON&
michael@0 134 TaskbarPreviewButton::Button() {
michael@0 135 return mPreview->mThumbButtons[mIndex];
michael@0 136 }
michael@0 137
michael@0 138 nsresult
michael@0 139 TaskbarPreviewButton::Update() {
michael@0 140 return mPreview->UpdateButton(mIndex);
michael@0 141 }
michael@0 142
michael@0 143 } // namespace widget
michael@0 144 } // namespace mozilla
michael@0 145

mercurial