summaryrefslogtreecommitdiffstats
path: root/ppapi/cpp/dev/scrollbar_dev.cc
blob: 456190fbf412eff299c9538f5e92c3a50ecb51e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2010 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 <vector>

#include "ppapi/cpp/dev/scrollbar_dev.h"

#include "ppapi/cpp/common.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/module_impl.h"
#include "ppapi/cpp/rect.h"

namespace pp {

namespace {

template <> const char* interface_name<PPB_Scrollbar_Dev>() {
  return PPB_SCROLLBAR_DEV_INTERFACE;
}

}  // namespace

Scrollbar_Dev::Scrollbar_Dev(PP_Resource resource) : Widget_Dev(resource) {
}

Scrollbar_Dev::Scrollbar_Dev(const Instance& instance, bool vertical) {
  if (!has_interface<PPB_Scrollbar_Dev>())
    return;
  PassRefFromConstructor(get_interface<PPB_Scrollbar_Dev>()->Create(
      instance.pp_instance(), BoolToPPBool(vertical)));
}

Scrollbar_Dev::Scrollbar_Dev(const Scrollbar_Dev& other)
    : Widget_Dev(other) {
}

uint32_t Scrollbar_Dev::GetThickness() {
  if (!has_interface<PPB_Scrollbar_Dev>())
    return 0;
  return get_interface<PPB_Scrollbar_Dev>()->GetThickness();
}

uint32_t Scrollbar_Dev::GetValue() {
  if (!has_interface<PPB_Scrollbar_Dev>())
    return 0;
  return get_interface<PPB_Scrollbar_Dev>()->GetValue(pp_resource());
}

void Scrollbar_Dev::SetValue(uint32_t value) {
  if (has_interface<PPB_Scrollbar_Dev>())
    get_interface<PPB_Scrollbar_Dev>()->SetValue(pp_resource(), value);
}

void Scrollbar_Dev::SetDocumentSize(uint32_t size) {
  if (has_interface<PPB_Scrollbar_Dev>())
    get_interface<PPB_Scrollbar_Dev>()->SetDocumentSize(pp_resource(), size);
}

void Scrollbar_Dev::SetTickMarks(const Rect* tick_marks, uint32_t count) {
  if (!has_interface<PPB_Scrollbar_Dev>())
    return;

  std::vector<PP_Rect> temp;
  temp.resize(count);
  for (uint32_t i = 0; i < count; ++i)
    temp[i] = tick_marks[i];

  get_interface<PPB_Scrollbar_Dev>()->SetTickMarks(
      pp_resource(), count ? &temp[0] : NULL, count);
}

void Scrollbar_Dev::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) {
  if (has_interface<PPB_Scrollbar_Dev>())
    get_interface<PPB_Scrollbar_Dev>()->ScrollBy(pp_resource(),
                                                 unit,
                                                 multiplier);
}

}  // namespace pp