OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_PROXY_PPB_FONT_PROXY_H_ | 5 #ifndef PPAPI_PROXY_PPB_FONT_PROXY_H_ |
6 #define PPAPI_PROXY_PPB_FONT_PROXY_H_ | 6 #define PPAPI_PROXY_PPB_FONT_PROXY_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "ppapi/c/pp_instance.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "ppapi/c/pp_resource.h" | |
11 #include "ppapi/proxy/host_resource.h" | 10 #include "ppapi/proxy/host_resource.h" |
12 #include "ppapi/proxy/interface_proxy.h" | 11 #include "ppapi/proxy/interface_proxy.h" |
| 12 #include "ppapi/proxy/plugin_resource.h" |
| 13 #include "ppapi/shared_impl/webkit_forwarding.h" |
| 14 #include "ppapi/thunk/ppb_font_api.h" |
13 | 15 |
14 struct PPB_Font_Dev; | 16 struct PPB_Font_Dev; |
15 | 17 |
16 namespace pp { | 18 namespace pp { |
17 namespace proxy { | 19 namespace proxy { |
18 | 20 |
19 struct PPBFont_DrawTextAt_Params; | |
20 struct SerializedFontDescription; | |
21 class SerializedVarReceiveInput; | 21 class SerializedVarReceiveInput; |
22 | 22 |
23 class PPB_Font_Proxy : public InterfaceProxy { | 23 class PPB_Font_Proxy : public InterfaceProxy { |
24 public: | 24 public: |
25 PPB_Font_Proxy(Dispatcher* dispatcher, const void* target_interface); | 25 PPB_Font_Proxy(Dispatcher* dispatcher, const void* target_interface); |
26 virtual ~PPB_Font_Proxy(); | 26 virtual ~PPB_Font_Proxy(); |
27 | 27 |
28 static const Info* GetInfo(); | 28 static const Info* GetInfo(); |
29 | 29 |
30 const PPB_Font_Dev* ppb_font_target() const { | |
31 return static_cast<const PPB_Font_Dev*>(target_interface()); | |
32 } | |
33 | |
34 // InterfaceProxy implementation. | 30 // InterfaceProxy implementation. |
35 virtual bool OnMessageReceived(const IPC::Message& msg); | 31 virtual bool OnMessageReceived(const IPC::Message& msg); |
36 | 32 |
37 private: | 33 private: |
38 // Message handlers. | 34 DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); |
39 void OnMsgCreate(PP_Instance instance, | 35 }; |
40 const SerializedFontDescription& in_description, | |
41 HostResource* result, | |
42 SerializedFontDescription* out_description, | |
43 std::string* out_metrics); | |
44 void OnMsgDrawTextAt(SerializedVarReceiveInput text, | |
45 const PPBFont_DrawTextAt_Params& params, | |
46 PP_Bool* result); | |
47 void OnMsgMeasureText(HostResource font, | |
48 SerializedVarReceiveInput text, | |
49 PP_Bool text_is_rtl, | |
50 PP_Bool override_direction, | |
51 int32_t* result); | |
52 void OnMsgCharacterOffsetForPixel(HostResource font, | |
53 SerializedVarReceiveInput text, | |
54 PP_Bool text_is_rtl, | |
55 PP_Bool override_direction, | |
56 int32_t pixel_pos, | |
57 uint32_t* result); | |
58 void OnMsgPixelOffsetForCharacter(HostResource font, | |
59 SerializedVarReceiveInput text, | |
60 PP_Bool text_is_rtl, | |
61 PP_Bool override_direction, | |
62 uint32_t char_offset, | |
63 int32_t* result); | |
64 | 36 |
65 DISALLOW_COPY_AND_ASSIGN(PPB_Font_Proxy); | 37 class Font : public PluginResource, |
| 38 public ppapi::thunk::PPB_Font_API { |
| 39 public: |
| 40 // Note that there isn't a "real" resource in the renderer backing a font, |
| 41 // it lives entirely in the plugin process. So the resource ID in the host |
| 42 // resource should be 0. However, various code assumes the instance in the |
| 43 // host resource is valid (this is how resources are associated with |
| 44 // instances), so that should be set. |
| 45 Font(const HostResource& resource, const PP_FontDescription_Dev& desc); |
| 46 virtual ~Font(); |
| 47 |
| 48 // ResourceObjectBase. |
| 49 virtual ppapi::thunk::PPB_Font_API* AsFont_API() OVERRIDE; |
| 50 |
| 51 // PluginResource overrides. |
| 52 virtual Font* AsFont() OVERRIDE; |
| 53 |
| 54 // PPB_Font_API implementation. |
| 55 virtual PP_Bool Describe(PP_FontDescription_Dev* description, |
| 56 PP_FontMetrics_Dev* metrics) OVERRIDE; |
| 57 virtual PP_Bool DrawTextAt(PP_Resource image_data, |
| 58 const PP_TextRun_Dev* text, |
| 59 const PP_Point* position, |
| 60 uint32_t color, |
| 61 const PP_Rect* clip, |
| 62 PP_Bool image_data_is_opaque) OVERRIDE; |
| 63 virtual int32_t MeasureText(const PP_TextRun_Dev* text) OVERRIDE; |
| 64 virtual uint32_t CharacterOffsetForPixel(const PP_TextRun_Dev* text, |
| 65 int32_t pixel_position) OVERRIDE; |
| 66 virtual int32_t PixelOffsetForCharacter(const PP_TextRun_Dev* text, |
| 67 uint32_t char_offset) OVERRIDE; |
| 68 |
| 69 private: |
| 70 // Posts the given closure to the WebKit thread and waits on the |
| 71 // webkit_event_ for the task to continue. |
| 72 void RunOnWebKitThread(const base::Closure& task); |
| 73 |
| 74 base::WaitableEvent webkit_event_; |
| 75 |
| 76 scoped_ptr<pp::shared_impl::WebKitForwarding::Font> font_forwarding_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(Font); |
66 }; | 79 }; |
67 | 80 |
68 } // namespace proxy | 81 } // namespace proxy |
69 } // namespace pp | 82 } // namespace pp |
70 | 83 |
71 #endif // PPAPI_PROXY_PPB_FONT_PROXY_H_ | 84 #endif // PPAPI_PROXY_PPB_FONT_PROXY_H_ |
OLD | NEW |