1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "pdf/fading_control.h"
9 #include "base/logging.h"
10 #include "pdf/draw_utils.h"
11 #include "pdf/resource_consts.h"
13 namespace chrome_pdf
{
15 FadingControl::FadingControl()
16 : alpha_shift_(0), timer_id_(0) {
19 FadingControl::~FadingControl() {
22 void FadingControl::OnTimerFired(uint32 timer_id
) {
23 if (timer_id
== timer_id_
) {
24 int32 new_alpha
= transparency() + alpha_shift_
;
25 if (new_alpha
<= kTransparentAlpha
) {
30 if (new_alpha
>= kOpaqueAlpha
) {
31 AdjustTransparency(kOpaqueAlpha
, true);
36 AdjustTransparency(static_cast<uint8
>(new_alpha
), true);
37 timer_id_
= owner()->ScheduleTimer(id(), kFadingTimeoutMs
);
41 // Fade In/Out control depending on visible flag over the time of time_ms.
42 void FadingControl::Fade(bool show
, uint32 time_ms
) {
44 // Check if we already in the same state.
45 if (!visible() && !show
)
47 if (!visible() && show
) {
49 AdjustTransparency(kTransparentAlpha
, false);
52 if (transparency() == kOpaqueAlpha
&& show
) {
57 int delta
= show
? kOpaqueAlpha
- transparency() : transparency();
59 static_cast<double>(delta
) * kFadingTimeoutMs
/ time_ms
;
63 alpha_shift_
= static_cast<int>(ceil(shift
));
65 if (alpha_shift_
== 0)
68 // If disabling, make alpha shift negative.
70 alpha_shift_
= -alpha_shift_
;
72 timer_id_
= owner()->ScheduleTimer(id(), kFadingTimeoutMs
);
75 } // namespace chrome_pdf