Use the host instead of the title for streamlined hosted apps.
[chromium-blink-merge.git] / pdf / page_indicator.cc
blob6177074b26f023e03b15862de65a4cb0ded1b123
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/page_indicator.h"
7 #include "base/logging.h"
8 #include "base/strings/string_util.h"
9 #include "pdf/draw_utils.h"
10 #include "pdf/number_image_generator.h"
11 #include "pdf/resource_consts.h"
13 namespace chrome_pdf {
16 PageIndicator::PageIndicator()
17 : current_page_(0),
18 splash_timeout_(kPageIndicatorSplashTimeoutMs),
19 fade_timeout_(kPageIndicatorScrollFadeTimeoutMs),
20 always_visible_(false) {
23 PageIndicator::~PageIndicator() {
26 bool PageIndicator::CreatePageIndicator(
27 uint32 id,
28 bool visible,
29 Control::Owner* delegate,
30 NumberImageGenerator* number_image_generator,
31 bool always_visible) {
32 number_image_generator_ = number_image_generator;
33 always_visible_ = always_visible;
35 pp::Rect rc;
36 bool res = Control::Create(id, rc, visible, delegate);
37 return res;
40 void PageIndicator::Configure(const pp::Point& origin,
41 const pp::ImageData& background) {
42 background_ = background;
43 pp::Rect rc(origin, background_.size());
44 Control::SetRect(rc, false);
47 void PageIndicator::set_current_page(int current_page) {
48 if (current_page_ < 0)
49 return;
51 current_page_ = current_page;
54 void PageIndicator::Paint(pp::ImageData* image_data, const pp::Rect& rc) {
55 if (!visible())
56 return;
58 pp::Rect draw_rc = rc.Intersect(rect());
59 if (draw_rc.IsEmpty())
60 return;
62 // Copying the background image to a temporary buffer.
63 pp::ImageData buffer(owner()->GetInstance(), background_.format(),
64 background_.size(), false);
65 CopyImage(background_, pp::Rect(background_.size()),
66 &buffer, pp::Rect(background_.size()), false);
68 // Creating the page number image.
69 pp::ImageData page_number_image;
70 number_image_generator_->GenerateImage(current_page_, &page_number_image);
72 pp::Point origin2(
73 (buffer.size().width() - page_number_image.size().width()) / 2.5,
74 (buffer.size().height() - page_number_image.size().height()) / 2);
76 // Drawing page number image on the buffer.
77 if (origin2.x() > 0 && origin2.y() > 0) {
78 CopyImage(page_number_image,
79 pp::Rect(pp::Point(), page_number_image.size()),
80 &buffer,
81 pp::Rect(origin2, page_number_image.size()),
82 false);
85 // Drawing the buffer.
86 pp::Point origin = draw_rc.point();
87 draw_rc.Offset(-rect().x(), -rect().y());
88 AlphaBlend(buffer, draw_rc, image_data, origin, transparency());
91 void PageIndicator::OnTimerFired(uint32 timer_id) {
92 FadingControl::OnTimerFired(timer_id);
93 if (timer_id == fade_out_timer_id_) {
94 Fade(false, fade_timeout_);
98 void PageIndicator::ResetFadeOutTimer() {
99 fade_out_timer_id_ =
100 owner()->ScheduleTimer(id(), splash_timeout_);
103 void PageIndicator::OnFadeInComplete() {
104 if (!always_visible_)
105 ResetFadeOutTimer();
108 void PageIndicator::Splash() {
109 Splash(kPageIndicatorSplashTimeoutMs, kPageIndicatorScrollFadeTimeoutMs);
112 void PageIndicator::Splash(uint32 splash_timeout, uint32 fade_timeout) {
113 splash_timeout_ = splash_timeout;
114 fade_timeout_ = fade_timeout;
115 if (!always_visible_)
116 fade_out_timer_id_ = 0;
117 Fade(true, fade_timeout_);
120 int PageIndicator::GetYPosition(
121 int vertical_scrollbar_y, int document_height, int plugin_height) {
122 double percent = static_cast<double>(vertical_scrollbar_y) / document_height;
123 return (plugin_height - rect().height()) * percent;
126 } // namespace chrome_pdf