Valgrind: Add a new suppression and widen some existing suppressions.
[chromium-blink-merge.git] / pdf / control.cc
blob12bb7ed1689f872611f45124b139c33563d40891
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 // painting (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 if (buffer.is_null())
53 return;
55 pp::Rect draw_rc = pp::Rect(image_data->size()).Intersect(rect());
56 pp::Rect ctrl_rc = pp::Rect(rect().point() - draw_rc.point(), draw_rc.size());
57 CopyImage(*image_data, draw_rc, &buffer, ctrl_rc, false);
59 // Temporary move control to origin (0,0) and draw it into temp buffer.
60 // Move to the original position afterward. Since this is going on temp
61 // buffer, we don't need to invalidate here.
62 pp::Rect temp = rect();
63 MoveTo(pp::Point(0, 0), false);
64 Paint(&buffer, ctrl_rc);
65 MoveTo(temp.point(), false);
67 std::list<pp::Rect>::const_iterator iter;
68 for (iter = rects.begin(); iter != rects.end(); ++iter) {
69 pp::Rect draw_rc = rect().Intersect(*iter);
70 if (!draw_rc.IsEmpty()) {
71 // Copy requested rect from the buffer image.
72 pp::Rect src_rc = draw_rc;
73 src_rc.Offset(-rect().x(), -rect().y());
74 CopyImage(buffer, src_rc, image_data, draw_rc, false);
79 void Control::Show(bool visible, bool invalidate) {
80 if (visible_ != visible) {
81 visible_ = visible;
82 if (invalidate)
83 owner_->Invalidate(id_, rc_);
87 void Control::AdjustTransparency(uint8 transparency, bool invalidate) {
88 if (transparency_ != transparency) {
89 transparency_ = transparency;
90 if (invalidate && visible_)
91 owner_->Invalidate(id_, rc_);
95 void Control::MoveBy(const pp::Point& offset, bool invalidate) {
96 pp::Rect old_rc = rc_;
97 rc_.Offset(offset);
98 if (invalidate && visible_) {
99 owner()->Invalidate(id(), old_rc);
100 owner()->Invalidate(id(), rect());
104 void Control::SetRect(const pp::Rect& rc, bool invalidate) {
105 pp::Rect old_rc = rc_;
106 rc_ = rc;
107 if (invalidate && visible_) {
108 owner()->Invalidate(id(), old_rc);
109 owner()->Invalidate(id(), rect());
113 void Control::MoveTo(const pp::Point& origin, bool invalidate) {
114 MoveBy(origin - rc_.point(), invalidate);
117 } // namespace chrome_pdf