OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 UI_BASE_WEBUI_WEB_UI_UTIL_H_ | 5 #ifndef UI_BASE_WEBUI_WEB_UI_UTIL_H_ |
6 #define UI_BASE_WEBUI_WEB_UI_UTIL_H_ | 6 #define UI_BASE_WEBUI_WEB_UI_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "ui/base/layout.h" | |
13 #include "ui/base/ui_base_export.h" | 12 #include "ui/base/ui_base_export.h" |
14 #include "ui/base/window_open_disposition.h" | 13 #include "ui/base/window_open_disposition.h" |
15 | 14 |
16 class GURL; | 15 class GURL; |
17 class SkBitmap; | 16 class SkBitmap; |
18 | 17 |
19 namespace webui { | 18 namespace webui { |
20 | 19 |
21 // Convenience routine to convert SkBitmap object to data url | 20 // Convenience routine to convert SkBitmap object to data url |
22 // so that it can be used in WebUI. | 21 // so that it can be used in WebUI. |
23 UI_BASE_EXPORT std::string GetBitmapDataUrl(const SkBitmap& bitmap); | 22 UI_BASE_EXPORT std::string GetBitmapDataUrl(const SkBitmap& bitmap); |
24 | 23 |
25 // Convenience routine to get data url that corresponds to given | 24 // Convenience routine to get data url that corresponds to given |
26 // resource_id as a bitmap. This function does not check if the | 25 // resource_id as a bitmap. This function does not check if the |
27 // resource for the |resource_id| is a bitmap, therefore it is the | 26 // resource for the |resource_id| is a bitmap, therefore it is the |
28 // caller's responsibility to make sure the resource is indeed a | 27 // caller's responsibility to make sure the resource is indeed a |
29 // bitmap. Returns empty string if a resource does not exist for given | 28 // bitmap. Returns empty string if a resource does not exist for given |
30 // |resource_id|. | 29 // |resource_id|. |
31 UI_BASE_EXPORT std::string GetBitmapDataUrlFromResource(int resource_id); | 30 UI_BASE_EXPORT std::string GetBitmapDataUrlFromResource(int resource_id); |
32 | 31 |
33 // Extracts a disposition from click event arguments. |args| should contain | 32 // Extracts a disposition from click event arguments. |args| should contain |
34 // an integer button and booleans alt key, ctrl key, meta key, and shift key | 33 // an integer button and booleans alt key, ctrl key, meta key, and shift key |
35 // (in that order), starting at |start_index|. | 34 // (in that order), starting at |start_index|. |
36 UI_BASE_EXPORT WindowOpenDisposition | 35 UI_BASE_EXPORT WindowOpenDisposition |
37 GetDispositionFromClick(const base::ListValue* args, int start_index); | 36 GetDispositionFromClick(const base::ListValue* args, int start_index); |
38 | 37 |
39 // Given a scale factor such as "1x", "2x" or "1.99x", sets |scale_factor| to | 38 // Pares a formatted scale factor string into float and sets to |scale_factor|. |
40 // the closest ScaleFactor enum value for this scale factor. If string can not | |
41 // be parsed, then |scale_factor| is set to SCALE_FACTOR_100P, and false is | |
42 // returned. | |
43 UI_BASE_EXPORT bool ParseScaleFactor(const base::StringPiece& identifier, | 39 UI_BASE_EXPORT bool ParseScaleFactor(const base::StringPiece& identifier, |
44 ui::ScaleFactor* scale_factor); | 40 float* scale_factor); |
45 | 41 |
46 // Parses a URL containing some path @{scale}x. If it does not contain a scale | 42 // Parses a URL containing some path @{scale}x. If it does not contain a scale |
47 // factor then the default scale factor is returned. | 43 // factor then the default scale factor is returned. |
48 UI_BASE_EXPORT void ParsePathAndScale(const GURL& url, | 44 UI_BASE_EXPORT void ParsePathAndScale(const GURL& url, |
49 std::string* path, | 45 std::string* path, |
50 ui::ScaleFactor* scale_factor); | 46 float* scale_factor); |
51 | 47 |
52 // Helper function to set the font family, size, and text direction into the | 48 // Helper function to set the font family, size, and text direction into the |
53 // given dictionary. | 49 // given dictionary. |
54 UI_BASE_EXPORT void SetFontAndTextDirection( | 50 UI_BASE_EXPORT void SetFontAndTextDirection( |
55 base::DictionaryValue* localized_strings); | 51 base::DictionaryValue* localized_strings); |
56 | 52 |
57 } // namespace webui | 53 } // namespace webui |
58 | 54 |
59 #endif // UI_BASE_WEBUI_WEB_UI_UTIL_H_ | 55 #endif // UI_BASE_WEBUI_WEB_UI_UTIL_H_ |
OLD | NEW |