Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / child / browser_font_resource_trusted.h
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_CHILD_BROWSER_FONT_RESOURCE_TRUSTED_H_
6 #define CONTENT_CHILD_BROWSER_FONT_RESOURCE_TRUSTED_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ppapi/c/pp_bool.h"
13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_resource.h"
15 #include "ppapi/c/pp_stdint.h"
16 #include "ppapi/proxy/plugin_resource.h"
17 #include "ppapi/shared_impl/ppapi_preferences.h"
18 #include "ppapi/thunk/ppb_browser_font_trusted_api.h"
19
20 class SkCanvas;
21
22 namespace blink {
23 class WebFont;
24 }
25
26 namespace content {
27
28 class BrowserFontResource_Trusted
29     : public ppapi::proxy::PluginResource,
30       public ppapi::thunk::PPB_BrowserFont_Trusted_API {
31  public:
32   BrowserFontResource_Trusted(ppapi::proxy::Connection connection,
33                               PP_Instance instance,
34                               const PP_BrowserFont_Trusted_Description& desc,
35                               const ppapi::Preferences& prefs);
36
37   // Validates the parameters in thee description. Can be called on any thread.
38   static bool IsPPFontDescriptionValid(
39       const PP_BrowserFont_Trusted_Description& desc);
40
41   // Resource override.
42   ::ppapi::thunk::PPB_BrowserFont_Trusted_API* AsPPB_BrowserFont_Trusted_API()
43       override;
44
45   // PPB_BrowserFont_Trusted_API implementation.
46   PP_Bool Describe(PP_BrowserFont_Trusted_Description* description,
47                    PP_BrowserFont_Trusted_Metrics* metrics) override;
48   PP_Bool DrawTextAt(PP_Resource image_data,
49                      const PP_BrowserFont_Trusted_TextRun* text,
50                      const PP_Point* position,
51                      uint32_t color,
52                      const PP_Rect* clip,
53                      PP_Bool image_data_is_opaque) override;
54   int32_t MeasureText(const PP_BrowserFont_Trusted_TextRun* text) override;
55   uint32_t CharacterOffsetForPixel(const PP_BrowserFont_Trusted_TextRun* text,
56                                    int32_t pixel_position) override;
57   int32_t PixelOffsetForCharacter(const PP_BrowserFont_Trusted_TextRun* text,
58                                   uint32_t char_offset) override;
59
60  private:
61   ~BrowserFontResource_Trusted() override;
62
63   // Internal version of DrawTextAt that takes a mapped PlatformCanvas.
64   void DrawTextToCanvas(SkCanvas* destination,
65                         const PP_BrowserFont_Trusted_TextRun& text,
66                         const PP_Point* position,
67                         uint32_t color,
68                         const PP_Rect* clip,
69                         PP_Bool image_data_is_opaque);
70
71  private:
72   scoped_ptr<blink::WebFont> font_;
73
74   DISALLOW_COPY_AND_ASSIGN(BrowserFontResource_Trusted);
75 };
76
77 }  // namespace content
78
79 #endif  // CONTENT_CHILD_BROWSER_FONT_RESOURCE_TRUSTED_H_