summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl/webkit_forwarding.h
blob: 4f45344011df15182e91eaa6d2447e7b83423469 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2011 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.

#ifndef PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_
#define PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_

#include <string>

#include "ppapi/c/pp_bool.h"
#include "ppapi/c/pp_stdint.h"

struct PP_FontDescription_Dev;
struct PP_FontMetrics_Dev;
struct PP_Point;
struct PP_Rect;

namespace base {
class WaitableEvent;
}

namespace skia {
class PlatformCanvas;
}

namespace ppapi {

class WebKitForwarding {
 public:
  class Font {
   public:
    // C++ version of PP_TextRun_Dev. Since the functions below will be called
    // on an alternate thread in the proxy, and since there are different
    // methods of converting PP_Var -> strings in the plugin and the proxy, we
    // can't use PP_Vars in the Do* functions below.
    struct TextRun {
      std::string text;
      bool rtl;
      bool override_direction;
    };

    // DoDrawText takes too many arguments to be used with base::Bind, so we
    // use this struct to hold them.
    struct DrawTextParams {
      DrawTextParams(skia::PlatformCanvas* destination_arg,
                     const TextRun& text_arg,
                     const PP_Point* position_arg,
                     uint32_t color_arg,
                     const PP_Rect* clip_arg,
                     PP_Bool image_data_is_opaque_arg);
      ~DrawTextParams();

      skia::PlatformCanvas* destination;
      const TextRun& text;
      const PP_Point* position;
      uint32_t color;
      const PP_Rect* clip;
      PP_Bool image_data_is_opaque;
    };

    virtual ~Font();

    // The face name in the description is not filled in to avoid a dependency
    // on creating vars. Instead, the face name is placed into the given
    // string. See class description for waitable_event documentation. If
    // non-null, the given event will be set on completion.
    virtual void Describe(base::WaitableEvent* event,
                          PP_FontDescription_Dev* description,
                          std::string* face,
                          PP_FontMetrics_Dev* metrics,
                          PP_Bool* result) = 0;
    virtual void DrawTextAt(base::WaitableEvent* event,
                            const DrawTextParams& params) = 0;
    virtual void MeasureText(base::WaitableEvent* event,
                             const TextRun& text,
                             int32_t* result) = 0;
    virtual void CharacterOffsetForPixel(base::WaitableEvent* event,
                                         const TextRun& text,
                                         int32_t pixel_position,
                                         uint32_t* result) = 0;
    virtual void PixelOffsetForCharacter(base::WaitableEvent* event,
                                         const TextRun& text,
                                         uint32_t char_offset,
                                         int32_t* result) = 0;
  };

  virtual ~WebKitForwarding();

  // Creates a new font with the given description. The desc_face is the face
  // name already extracted from the description. The caller owns the result
  // pointer, which will never be NULL. If non-null, the given event will be
  // set on completion.
  virtual void CreateFontForwarding(base::WaitableEvent* event,
                                    const PP_FontDescription_Dev& desc,
                                    const std::string& desc_face,
                                    Font** result) = 0;

};

}  // namespace ppapi

#endif  // PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_