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 #include "webkit/plugins/ppapi/ppb_font_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_font_impl.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_font_dev.h" | 7 #include "ppapi/c/dev/ppb_font_dev.h" |
8 #include "ppapi/shared_impl/font_impl.h" | 8 #include "ppapi/shared_impl/font_impl.h" |
9 #include "ppapi/shared_impl/ppapi_preferences.h" | 9 #include "ppapi/shared_impl/ppapi_preferences.h" |
10 #include "ppapi/shared_impl/var.h" | 10 #include "ppapi/shared_impl/var.h" |
11 #include "ppapi/thunk/enter.h" | 11 #include "ppapi/thunk/enter.h" |
12 #include "ppapi/thunk/thunk.h" | 12 #include "ppapi/thunk/thunk.h" |
13 #include "webkit/plugins/ppapi/common.h" | 13 #include "webkit/plugins/ppapi/common.h" |
14 #include "webkit/plugins/ppapi/plugin_module.h" | 14 #include "webkit/plugins/ppapi/plugin_module.h" |
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
16 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 16 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
| 17 #include "webkit/plugins/ppapi/resource_helper.h" |
17 #include "webkit/plugins/ppapi/string.h" | 18 #include "webkit/plugins/ppapi/string.h" |
18 | 19 |
19 using ppapi::StringVar; | 20 using ppapi::StringVar; |
20 using ppapi::thunk::EnterResource; | 21 using ppapi::thunk::EnterResource; |
21 using ppapi::thunk::PPB_ImageData_API; | 22 using ppapi::thunk::PPB_ImageData_API; |
22 using ppapi::WebKitForwarding; | 23 using ppapi::WebKitForwarding; |
23 | 24 |
24 namespace webkit { | 25 namespace webkit { |
25 namespace ppapi { | 26 namespace ppapi { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Converts the given PP_TextRun to a TextRun, returning true on success. | 30 // Converts the given PP_TextRun to a TextRun, returning true on success. |
30 // False means the input was invalid. | 31 // False means the input was invalid. |
31 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, | 32 bool PPTextRunToTextRun(const PP_TextRun_Dev* run, |
32 WebKitForwarding::Font::TextRun* output) { | 33 WebKitForwarding::Font::TextRun* output) { |
33 StringVar* text_string = StringVar::FromPPVar(run->text); | 34 StringVar* text_string = StringVar::FromPPVar(run->text); |
34 if (!text_string) | 35 if (!text_string) |
35 return false; | 36 return false; |
36 | 37 |
37 output->text = text_string->value(); | 38 output->text = text_string->value(); |
38 output->rtl = PPBoolToBool(run->rtl); | 39 output->rtl = PPBoolToBool(run->rtl); |
39 output->override_direction = PPBoolToBool(run->override_direction); | 40 output->override_direction = PPBoolToBool(run->override_direction); |
40 return true; | 41 return true; |
41 } | 42 } |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 PPB_Font_Impl::PPB_Font_Impl(PluginInstance* instance, | 46 PPB_Font_Impl::PPB_Font_Impl(PP_Instance pp_instance, |
46 const PP_FontDescription_Dev& desc) | 47 const PP_FontDescription_Dev& desc) |
47 : Resource(instance) { | 48 : Resource(pp_instance) { |
48 StringVar* face_name = StringVar::FromPPVar(desc.face); | 49 StringVar* face_name = StringVar::FromPPVar(desc.face); |
49 | 50 |
50 WebKitForwarding::Font* result = NULL; | 51 WebKitForwarding::Font* result = NULL; |
51 instance->module()->GetWebKitForwarding()->CreateFontForwarding( | 52 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
52 NULL, desc, face_name ? face_name->value() : std::string(), | 53 if (plugin_instance) { |
53 instance->delegate()->GetPreferences(), &result); | 54 plugin_instance->module()->GetWebKitForwarding()->CreateFontForwarding( |
| 55 NULL, desc, face_name ? face_name->value() : std::string(), |
| 56 plugin_instance->delegate()->GetPreferences(), &result); |
| 57 } |
54 font_forwarding_.reset(result); | 58 font_forwarding_.reset(result); |
55 } | 59 } |
56 | 60 |
57 PPB_Font_Impl::~PPB_Font_Impl() { | 61 PPB_Font_Impl::~PPB_Font_Impl() { |
58 } | 62 } |
59 | 63 |
60 // static | 64 // static |
61 PP_Resource PPB_Font_Impl::Create(PluginInstance* instance, | 65 PP_Resource PPB_Font_Impl::Create(PP_Instance instance, |
62 const PP_FontDescription_Dev& description) { | 66 const PP_FontDescription_Dev& description) { |
63 if (!::ppapi::FontImpl::IsPPFontDescriptionValid(description)) | 67 if (!::ppapi::FontImpl::IsPPFontDescriptionValid(description)) |
64 return 0; | 68 return 0; |
65 return (new PPB_Font_Impl(instance, description))->GetReference(); | 69 return (new PPB_Font_Impl(instance, description))->GetReference(); |
66 } | 70 } |
67 | 71 |
68 ::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() { | 72 ::ppapi::thunk::PPB_Font_API* PPB_Font_Impl::AsPPB_Font_API() { |
69 return this; | 73 return this; |
70 } | 74 } |
71 | 75 |
72 PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description, | 76 PP_Bool PPB_Font_Impl::Describe(PP_FontDescription_Dev* description, |
73 PP_FontMetrics_Dev* metrics) { | 77 PP_FontMetrics_Dev* metrics) { |
74 std::string face; | 78 std::string face; |
75 PP_Bool result = PP_FALSE; | 79 PP_Bool result = PP_FALSE; |
76 font_forwarding_->Describe(NULL, description, &face, metrics, &result); | 80 font_forwarding_->Describe(NULL, description, &face, metrics, &result); |
77 if (!result) | 81 if (!result) |
78 return PP_FALSE; | 82 return PP_FALSE; |
79 | 83 |
| 84 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 85 if (!plugin_module) |
| 86 return PP_FALSE; |
| 87 |
80 // Convert the string. | 88 // Convert the string. |
81 description->face = StringVar::StringToPPVar( | 89 description->face = StringVar::StringToPPVar(plugin_module->pp_module(), |
82 instance()->module()->pp_module(), face); | 90 face); |
83 return PP_TRUE; | 91 return PP_TRUE; |
84 } | 92 } |
85 | 93 |
86 PP_Bool PPB_Font_Impl::DrawTextAt(PP_Resource image_data, | 94 PP_Bool PPB_Font_Impl::DrawTextAt(PP_Resource image_data, |
87 const PP_TextRun_Dev* text, | 95 const PP_TextRun_Dev* text, |
88 const PP_Point* position, | 96 const PP_Point* position, |
89 uint32_t color, | 97 uint32_t color, |
90 const PP_Rect* clip, | 98 const PP_Rect* clip, |
91 PP_Bool image_data_is_opaque) { | 99 PP_Bool image_data_is_opaque) { |
92 // Get and map the image data we're painting to. | 100 // Get and map the image data we're painting to. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 return this; | 159 return this; |
152 } | 160 } |
153 | 161 |
154 PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) { | 162 PP_Var PPB_Font_FunctionImpl::GetFontFamilies(PP_Instance instance) { |
155 return PP_MakeUndefined(); | 163 return PP_MakeUndefined(); |
156 } | 164 } |
157 | 165 |
158 } // namespace ppapi | 166 } // namespace ppapi |
159 } // namespace webkit | 167 } // namespace webkit |
160 | 168 |
OLD | NEW |