summaryrefslogtreecommitdiffstats
path: root/pdf/fading_control.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-20 01:56:40 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-20 01:56:40 +0000
commit1b1e9effe9fa3b66dd1bcfff4b78455460f66c61 (patch)
treeca185a1ce62737b897b38ed77d8b8945dddec8df /pdf/fading_control.cc
parentf0d119a1eb1211961315c7ce31984134798dbb47 (diff)
downloadchromium_src-1b1e9effe9fa3b66dd1bcfff4b78455460f66c61.zip
chromium_src-1b1e9effe9fa3b66dd1bcfff4b78455460f66c61.tar.gz
chromium_src-1b1e9effe9fa3b66dd1bcfff4b78455460f66c61.tar.bz2
Add the pdf plugin's source in src\pdf.
I've updated gypi files to not use internal_pdf variable anymore, which was brought in from pdf repo's supplemental.gypi. R=thestig@chromium.org TBR=darin Review URL: https://codereview.chromium.org/294793003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271531 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'pdf/fading_control.cc')
-rw-r--r--pdf/fading_control.cc75
1 files changed, 75 insertions, 0 deletions
diff --git a/pdf/fading_control.cc b/pdf/fading_control.cc
new file mode 100644
index 0000000..7e4d8ef
--- /dev/null
+++ b/pdf/fading_control.cc
@@ -0,0 +1,75 @@
+// 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.
+
+#include "pdf/fading_control.h"
+
+#include <math.h>
+
+#include "base/logging.h"
+#include "pdf/draw_utils.h"
+#include "pdf/resource_consts.h"
+
+namespace chrome_pdf {
+
+FadingControl::FadingControl()
+ : alpha_shift_(0), timer_id_(0) {
+}
+
+FadingControl::~FadingControl() {
+}
+
+void FadingControl::OnTimerFired(uint32 timer_id) {
+ if (timer_id == timer_id_) {
+ int32 new_alpha = transparency() + alpha_shift_;
+ if (new_alpha <= kTransparentAlpha) {
+ Show(false, true);
+ OnFadeOutComplete();
+ return;
+ }
+ if (new_alpha >= kOpaqueAlpha) {
+ AdjustTransparency(kOpaqueAlpha, true);
+ OnFadeInComplete();
+ return;
+ }
+
+ AdjustTransparency(static_cast<uint8>(new_alpha), true);
+ timer_id_ = owner()->ScheduleTimer(id(), kFadingTimeoutMs);
+ }
+}
+
+// Fade In/Out control depending on visible flag over the time of time_ms.
+void FadingControl::Fade(bool show, uint32 time_ms) {
+ DCHECK(time_ms != 0);
+ // Check if we already in the same state.
+ if (!visible() && !show)
+ return;
+ if (!visible() && show) {
+ Show(show, false);
+ AdjustTransparency(kTransparentAlpha, false);
+ OnFadeOutComplete();
+ }
+ if (transparency() == kOpaqueAlpha && show) {
+ OnFadeInComplete();
+ return;
+ }
+
+ int delta = show ? kOpaqueAlpha - transparency() : transparency();
+ double shift =
+ static_cast<double>(delta) * kFadingTimeoutMs / time_ms;
+ if (shift > delta)
+ alpha_shift_ = delta;
+ else
+ alpha_shift_ = static_cast<int>(ceil(shift));
+
+ if (alpha_shift_ == 0)
+ alpha_shift_ = 1;
+
+ // If disabling, make alpha shift negative.
+ if (!show)
+ alpha_shift_ = -alpha_shift_;
+
+ timer_id_ = owner()->ScheduleTimer(id(), kFadingTimeoutMs);
+}
+
+} // namespace chrome_pdf