/src/mozilla-central/widget/gtk/TaskbarProgress.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "mozilla/Logging.h" |
8 | | |
9 | | #include "TaskbarProgress.h" |
10 | | #include "nsWindow.h" |
11 | | #include "WidgetUtils.h" |
12 | | #include "nsPIDOMWindow.h" |
13 | | |
14 | | using mozilla::LogLevel; |
15 | | static mozilla::LazyLogModule gGtkTaskbarProgressLog("nsIGtkTaskbarProgress"); |
16 | | |
17 | | /****************************************************************************** |
18 | | * TaskbarProgress |
19 | | ******************************************************************************/ |
20 | | |
21 | | NS_IMPL_ISUPPORTS(TaskbarProgress, nsIGtkTaskbarProgress, nsITaskbarProgress) |
22 | | |
23 | | TaskbarProgress::TaskbarProgress() |
24 | | : mPrimaryWindow(nullptr) |
25 | 0 | { |
26 | 0 | MOZ_LOG(gGtkTaskbarProgressLog, LogLevel::Info, |
27 | 0 | ("%p TaskbarProgress()", this)); |
28 | 0 | } |
29 | | |
30 | | TaskbarProgress::~TaskbarProgress() |
31 | 0 | { |
32 | 0 | MOZ_LOG(gGtkTaskbarProgressLog, LogLevel::Info, |
33 | 0 | ("%p ~TaskbarProgress()", this)); |
34 | 0 | } |
35 | | |
36 | | NS_IMETHODIMP |
37 | | TaskbarProgress::SetProgressState(nsTaskbarProgressState aState, |
38 | | uint64_t aCurrentValue, |
39 | | uint64_t aMaxValue) |
40 | 0 | { |
41 | 0 | #ifdef MOZ_X11 |
42 | 0 | NS_ENSURE_ARG_RANGE(aState, 0, STATE_PAUSED); |
43 | 0 |
|
44 | 0 | if (aState == STATE_NO_PROGRESS || aState == STATE_INDETERMINATE) { |
45 | 0 | NS_ENSURE_TRUE(aCurrentValue == 0, NS_ERROR_INVALID_ARG); |
46 | 0 | NS_ENSURE_TRUE(aMaxValue == 0, NS_ERROR_INVALID_ARG); |
47 | 0 | } |
48 | 0 |
|
49 | 0 | NS_ENSURE_TRUE((aCurrentValue <= aMaxValue), NS_ERROR_ILLEGAL_VALUE); |
50 | 0 |
|
51 | 0 | // See TaskbarProgress::SetPrimaryWindow: if we're running in headless |
52 | 0 | // mode, mPrimaryWindow will be null. |
53 | 0 | if (!mPrimaryWindow) { |
54 | 0 | return NS_OK; |
55 | 0 | } |
56 | 0 | |
57 | 0 | gulong progress; |
58 | 0 |
|
59 | 0 | if (aMaxValue == 0) { |
60 | 0 | progress = 0; |
61 | 0 | } else { |
62 | 0 | // Rounding down to ensure we don't set to 'full' until the operation |
63 | 0 | // is completely finished. |
64 | 0 | progress = (gulong) (((double)aCurrentValue / aMaxValue) * 100.0); |
65 | 0 | } |
66 | 0 |
|
67 | 0 | // Check if the resultant value is the same as the previous call, and |
68 | 0 | // ignore this update if it is. |
69 | 0 |
|
70 | 0 | if (progress == mCurrentProgress) { |
71 | 0 | return NS_OK; |
72 | 0 | } |
73 | 0 | |
74 | 0 | mCurrentProgress = progress; |
75 | 0 |
|
76 | 0 | MOZ_LOG(gGtkTaskbarProgressLog, LogLevel::Debug, |
77 | 0 | ("GtkTaskbarProgress::SetProgressState progress: %lu", progress)); |
78 | 0 |
|
79 | 0 | mPrimaryWindow->SetProgress(progress); |
80 | 0 | #endif |
81 | 0 |
|
82 | 0 | return NS_OK; |
83 | 0 | } |
84 | | |
85 | | NS_IMETHODIMP |
86 | | TaskbarProgress::SetPrimaryWindow(mozIDOMWindowProxy* aWindow) |
87 | 0 | { |
88 | 0 | NS_ENSURE_TRUE(aWindow != nullptr, NS_ERROR_ILLEGAL_VALUE); |
89 | 0 |
|
90 | 0 | auto* parent = nsPIDOMWindowOuter::From(aWindow); |
91 | 0 | RefPtr<nsIWidget> widget = mozilla::widget::WidgetUtils::DOMWindowToWidget(parent); |
92 | 0 |
|
93 | 0 | // Only nsWindows have a native window, HeadlessWidgets do not. Stop here if the |
94 | 0 | // window does not have one. |
95 | 0 | if (!widget->GetNativeData(NS_NATIVE_WINDOW)) { |
96 | 0 | return NS_OK; |
97 | 0 | } |
98 | 0 | |
99 | 0 | mPrimaryWindow = static_cast<nsWindow*>(widget.get()); |
100 | 0 |
|
101 | 0 | // Clear our current progress. We get a forced update from the DownloadsTaskbar |
102 | 0 | // after returning from this function - zeroing out our progress will make sure the |
103 | 0 | // new window gets the property set on it immediately, rather than waiting for the |
104 | 0 | // progress value to change (which could be a while depending on size.) |
105 | 0 | mCurrentProgress = 0; |
106 | 0 |
|
107 | 0 | MOZ_LOG(gGtkTaskbarProgressLog, LogLevel::Debug, |
108 | 0 | ("GtkTaskbarProgress::SetPrimaryWindow window: %p", mPrimaryWindow.get())); |
109 | 0 |
|
110 | 0 | return NS_OK; |
111 | 0 | } |