Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/thunk/thunk.h" | 5 #include "ppapi/thunk/thunk.h" |
| 6 #include "ppapi/thunk/enter.h" | 6 #include "ppapi/thunk/enter.h" |
| 7 #include "ppapi/thunk/ppb_browser_font_singleton_api.h" | 7 #include "ppapi/thunk/ppb_browser_font_singleton_api.h" |
| 8 #include "ppapi/thunk/ppb_browser_font_trusted_api.h" | 8 #include "ppapi/thunk/ppb_browser_font_trusted_api.h" |
| 9 #include "ppapi/thunk/resource_creation_api.h" | 9 #include "ppapi/thunk/resource_creation_api.h" |
| 10 | 10 |
| 11 namespace ppapi { | 11 namespace ppapi { |
| 12 namespace thunk { | 12 namespace thunk { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 typedef EnterResource<PPB_BrowserFont_Trusted_API> EnterBrowserFont; | 16 typedef EnterResource<PPB_BrowserFont_Trusted_API> EnterBrowserFont; |
| 17 | 17 |
| 18 PP_Var GetFontFamilies(PP_Instance instance) { | 18 PP_Var GetFontFamilies(PP_Instance instance) { |
| 19 EnterInstanceAPI<PPB_BrowserFont_Singleton_API> enter(instance); | 19 EnterInstanceAPI<PPB_BrowserFont_Singleton_API> enter(instance); |
| 20 if (enter.failed()) | 20 return enter.succeeded() ? |
| 21 return PP_MakeUndefined(); | 21 enter.functions()->GetFontFamilies(instance) : PP_MakeUndefined(); |
|
Peter Kasting
2014/07/09 02:11:26
I had to touch this file anyway, and since IsBrows
| |
| 22 return enter.functions()->GetFontFamilies(instance); | |
| 23 } | 22 } |
| 24 | 23 |
| 25 PP_Resource Create(PP_Instance instance, | 24 PP_Resource Create(PP_Instance instance, |
| 26 const PP_BrowserFont_Trusted_Description* description) { | 25 const PP_BrowserFont_Trusted_Description* description) { |
| 27 EnterResourceCreation enter(instance); | 26 EnterResourceCreation enter(instance); |
| 28 if (enter.failed()) | 27 return enter.succeeded() ? |
| 29 return 0; | 28 enter.functions()->CreateBrowserFont(instance, description) : 0; |
| 30 return enter.functions()->CreateBrowserFont(instance, description); | |
| 31 } | 29 } |
| 32 | 30 |
| 33 PP_Bool IsBrowserFont(PP_Resource resource) { | 31 PP_Bool IsBrowserFont(PP_Resource resource) { |
| 34 EnterBrowserFont enter(resource, false); | 32 EnterBrowserFont enter(resource, false); |
| 35 return enter.succeeded() ? PP_TRUE : PP_FALSE; | 33 return enter.succeeded() ? PP_TRUE : PP_FALSE; |
| 36 } | 34 } |
| 37 | 35 |
| 38 PP_Bool Describe(PP_Resource font_id, | 36 PP_Bool Describe(PP_Resource font_id, |
| 39 PP_BrowserFont_Trusted_Description* description, | 37 PP_BrowserFont_Trusted_Description* description, |
| 40 PP_BrowserFont_Trusted_Metrics* metrics) { | 38 PP_BrowserFont_Trusted_Metrics* metrics) { |
| 41 EnterBrowserFont enter(font_id, true); | 39 EnterBrowserFont enter(font_id, true); |
| 42 if (enter.failed()) | 40 return enter.succeeded() ? |
| 43 return PP_FALSE; | 41 enter.object()->Describe(description, metrics) : PP_FALSE; |
| 44 return enter.object()->Describe(description, metrics); | |
| 45 } | 42 } |
| 46 | 43 |
| 47 PP_Bool DrawTextAt(PP_Resource font_id, | 44 PP_Bool DrawTextAt(PP_Resource font_id, |
| 48 PP_Resource image_data, | 45 PP_Resource image_data, |
| 49 const PP_BrowserFont_Trusted_TextRun* text, | 46 const PP_BrowserFont_Trusted_TextRun* text, |
| 50 const PP_Point* position, | 47 const PP_Point* position, |
| 51 uint32_t color, | 48 uint32_t color, |
| 52 const PP_Rect* clip, | 49 const PP_Rect* clip, |
| 53 PP_Bool image_data_is_opaque) { | 50 PP_Bool image_data_is_opaque) { |
| 54 EnterBrowserFont enter(font_id, true); | 51 EnterBrowserFont enter(font_id, true); |
| 55 if (enter.failed()) | 52 return enter.succeeded() ? |
| 56 return PP_FALSE; | 53 enter.object()->DrawTextAt(image_data, text, position, color, clip, |
| 57 return enter.object()->DrawTextAt(image_data, text, position, color, clip, | 54 image_data_is_opaque) : |
| 58 image_data_is_opaque); | 55 PP_FALSE; |
| 59 } | 56 } |
| 60 | 57 |
| 61 int32_t MeasureText(PP_Resource font_id, | 58 int32_t MeasureText(PP_Resource font_id, |
| 62 const PP_BrowserFont_Trusted_TextRun* text) { | 59 const PP_BrowserFont_Trusted_TextRun* text) { |
| 63 EnterBrowserFont enter(font_id, true); | 60 EnterBrowserFont enter(font_id, true); |
| 64 if (enter.failed()) | 61 return enter.succeeded() ? enter.object()->MeasureText(text) : -1; |
| 65 return -1; | |
| 66 return enter.object()->MeasureText(text); | |
| 67 } | 62 } |
| 68 | 63 |
| 69 uint32_t CharacterOffsetForPixel(PP_Resource font_id, | 64 uint32_t CharacterOffsetForPixel(PP_Resource font_id, |
| 70 const PP_BrowserFont_Trusted_TextRun* text, | 65 const PP_BrowserFont_Trusted_TextRun* text, |
| 71 int32_t pixel_position) { | 66 int32_t pixel_position) { |
| 72 EnterBrowserFont enter(font_id, true); | 67 EnterBrowserFont enter(font_id, true); |
| 73 if (enter.failed()) | 68 return enter.succeeded() ? |
| 74 return -1; | 69 enter.object()->CharacterOffsetForPixel(text, pixel_position) : |
| 75 return enter.object()->CharacterOffsetForPixel(text, pixel_position); | 70 0xFFFFFFFF; |
| 76 } | 71 } |
| 77 | 72 |
| 78 int32_t PixelOffsetForCharacter(PP_Resource font_id, | 73 int32_t PixelOffsetForCharacter(PP_Resource font_id, |
| 79 const PP_BrowserFont_Trusted_TextRun* text, | 74 const PP_BrowserFont_Trusted_TextRun* text, |
| 80 uint32_t char_offset) { | 75 uint32_t char_offset) { |
| 81 EnterBrowserFont enter(font_id, true); | 76 EnterBrowserFont enter(font_id, true); |
| 82 if (enter.failed()) | 77 return enter.succeeded() ? |
| 83 return -1; | 78 enter.object()->PixelOffsetForCharacter(text, char_offset) : -1; |
| 84 return enter.object()->PixelOffsetForCharacter(text, char_offset); | |
| 85 } | 79 } |
| 86 | 80 |
| 87 const PPB_BrowserFont_Trusted_1_0 g_ppb_browser_font_trusted_thunk = { | 81 const PPB_BrowserFont_Trusted_1_0 g_ppb_browser_font_trusted_thunk = { |
| 88 &GetFontFamilies, | 82 &GetFontFamilies, |
| 89 &Create, | 83 &Create, |
| 90 &IsBrowserFont, | 84 &IsBrowserFont, |
| 91 &Describe, | 85 &Describe, |
| 92 &DrawTextAt, | 86 &DrawTextAt, |
| 93 &MeasureText, | 87 &MeasureText, |
| 94 &CharacterOffsetForPixel, | 88 &CharacterOffsetForPixel, |
| 95 &PixelOffsetForCharacter | 89 &PixelOffsetForCharacter |
| 96 }; | 90 }; |
| 97 | 91 |
| 98 } // namespace | 92 } // namespace |
| 99 | 93 |
| 100 const PPB_BrowserFont_Trusted_1_0* GetPPB_BrowserFont_Trusted_1_0_Thunk() { | 94 const PPB_BrowserFont_Trusted_1_0* GetPPB_BrowserFont_Trusted_1_0_Thunk() { |
| 101 return &g_ppb_browser_font_trusted_thunk; | 95 return &g_ppb_browser_font_trusted_thunk; |
| 102 } | 96 } |
| 103 | 97 |
| 104 } // namespace thunk | 98 } // namespace thunk |
| 105 } // namespace ppapi | 99 } // namespace ppapi |
| OLD | NEW |