Revert 272142 "Save running SW instance info, including its Site..."
[chromium-blink-merge.git] / pdf / control.cc
blob34b60ba814e325f0151da8b32d2fbf128931a494
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/control.h"
7 #include "base/logging.h"
8 #include "pdf/draw_utils.h"
10 namespace chrome_pdf {
12 Control::Control()
13 : id_(kInvalidControlId),
14 visible_(false),
15 owner_(NULL),
16 transparency_(kOpaqueAlpha) {
19 Control::~Control() {
22 bool Control::Create(uint32 id, const pp::Rect& rc,
23 bool visible, Owner* owner) {
24 DCHECK(owner);
25 if (owner_ || id == kInvalidControlId)
26 return false; // Already created or id is invalid.
27 id_ = id;
28 rc_ = rc;
29 visible_ = visible;
30 owner_ = owner;
31 return true;
34 bool Control::HandleEvent(const pp::InputEvent& event) {
35 return false;
38 void Control::PaintMultipleRects(pp::ImageData* image_data,
39 const std::list<pp::Rect>& rects) {
40 DCHECK(rects.size() > 0);
41 if (rects.size() == 1) {
42 Paint(image_data, rects.front());
43 return;
46 // Some rects in the input list may overlap. To prevent double
47 // paining (causes problems with semi-transparent controls) we'll
48 // paint control into buffer image data only once and copy requested
49 // rectangles.
50 pp::ImageData buffer(owner()->GetInstance(), image_data->format(),
51 rect().size(), false);
52 pp::Rect draw_rc = pp::Rect(image_data->size()).Intersect(rect());
53 pp::Rect ctrl_rc = pp::Rect(rect().point() - draw_rc.point(), draw_rc.size());
54 CopyImage(*image_data, draw_rc, &buffer, ctrl_rc, false);
56 // Temporary move control to origin (0,0) and draw it into temp buffer.
57 // Move to the original position afterward. Since this is going on temp
58 // buffer, we don't need to invalidate here.
59 pp::Rect temp = rect();
60 MoveTo(pp::Point(0, 0), false);
61 Paint(&buffer, ctrl_rc);
62 MoveTo(temp.point(), false);
64 std::list<pp::Rect>::const_iterator iter;
65 for (iter = rects.begin(); iter != rects.end(); ++iter) {
66 pp::Rect draw_rc = rect().Intersect(*iter);
67 if (!draw_rc.IsEmpty()) {
68 // Copy requested rect from the buffer image.
69 pp::Rect src_rc = draw_rc;
70 src_rc.Offset(-rect().x(), -rect().y());
71 CopyImage(buffer, src_rc, image_data, draw_rc, false);
76 void Control::Show(bool visible, bool invalidate) {
77 if (visible_ != visible) {
78 visible_ = visible;
79 if (invalidate)
80 owner_->Invalidate(id_, rc_);
84 void Control::AdjustTransparency(uint8 transparency, bool invalidate) {
85 if (transparency_ != transparency) {
86 transparency_ = transparency;
87 if (invalidate && visible_)
88 owner_->Invalidate(id_, rc_);
92 void Control::MoveBy(const pp::Point& offset, bool invalidate) {
93 pp::Rect old_rc = rc_;
94 rc_.Offset(offset);
95 if (invalidate && visible_) {
96 owner()->Invalidate(id(), old_rc);
97 owner()->Invalidate(id(), rect());
101 void Control::SetRect(const pp::Rect& rc, bool invalidate) {
102 pp::Rect old_rc = rc_;
103 rc_ = rc;
104 if (invalidate && visible_) {
105 owner()->Invalidate(id(), old_rc);
106 owner()->Invalidate(id(), rect());
110 void Control::MoveTo(const pp::Point& origin, bool invalidate) {
111 MoveBy(origin - rc_.point(), invalidate);
114 } // namespace chrome_pdf