| 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 #include "ui/base/webui/web_ui_util.h" | 5 #include "ui/base/webui/web_ui_util.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 CHECK(args->GetDouble(start_index++, &button)); | 69 CHECK(args->GetDouble(start_index++, &button)); |
| 70 CHECK(args->GetBoolean(start_index++, &alt_key)); | 70 CHECK(args->GetBoolean(start_index++, &alt_key)); |
| 71 CHECK(args->GetBoolean(start_index++, &ctrl_key)); | 71 CHECK(args->GetBoolean(start_index++, &ctrl_key)); |
| 72 CHECK(args->GetBoolean(start_index++, &meta_key)); | 72 CHECK(args->GetBoolean(start_index++, &meta_key)); |
| 73 CHECK(args->GetBoolean(start_index++, &shift_key)); | 73 CHECK(args->GetBoolean(start_index++, &shift_key)); |
| 74 return ui::DispositionFromClick( | 74 return ui::DispositionFromClick( |
| 75 button == 1.0, alt_key, ctrl_key, meta_key, shift_key); | 75 button == 1.0, alt_key, ctrl_key, meta_key, shift_key); |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool ParseScaleFactor(const base::StringPiece& identifier, | 78 bool ParseScaleFactor(const base::StringPiece& identifier, |
| 79 ui::ScaleFactor* scale_factor) { | 79 float* scale_factor) { |
| 80 *scale_factor = ui::SCALE_FACTOR_100P; | 80 *scale_factor = 1.0f; |
| 81 if (identifier.empty()) { | 81 if (identifier.empty()) { |
| 82 LOG(WARNING) << "Invalid scale factor format: " << identifier; | 82 LOG(WARNING) << "Invalid scale factor format: " << identifier; |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 if (*identifier.rbegin() != 'x') { | 86 if (*identifier.rbegin() != 'x') { |
| 87 LOG(WARNING) << "Invalid scale factor format: " << identifier; | 87 LOG(WARNING) << "Invalid scale factor format: " << identifier; |
| 88 return false; | 88 return false; |
| 89 } | 89 } |
| 90 | 90 |
| 91 double scale = 0; | 91 double scale = 0; |
| 92 std::string stripped; | 92 std::string stripped; |
| 93 identifier.substr(0, identifier.length() - 1).CopyToString(&stripped); | 93 identifier.substr(0, identifier.length() - 1).CopyToString(&stripped); |
| 94 if (!base::StringToDouble(stripped, &scale)) { | 94 if (!base::StringToDouble(stripped, &scale)) { |
| 95 LOG(WARNING) << "Invalid scale factor format: " << identifier; | 95 LOG(WARNING) << "Invalid scale factor format: " << identifier; |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 *scale_factor = scale; |
| 99 *scale_factor = ui::GetSupportedScaleFactor(static_cast<float>(scale)); | |
| 100 return true; | 99 return true; |
| 101 } | 100 } |
| 102 | 101 |
| 103 void ParsePathAndScale(const GURL& url, | 102 void ParsePathAndScale(const GURL& url, |
| 104 std::string* path, | 103 std::string* path, |
| 105 ui::ScaleFactor* scale_factor) { | 104 float* scale_factor) { |
| 106 *path = net::UnescapeURLComponent(url.path().substr(1), | 105 *path = net::UnescapeURLComponent(url.path().substr(1), |
| 107 (net::UnescapeRule::URL_SPECIAL_CHARS | | 106 (net::UnescapeRule::URL_SPECIAL_CHARS | |
| 108 net::UnescapeRule::SPACES)); | 107 net::UnescapeRule::SPACES)); |
| 109 if (scale_factor) | 108 if (scale_factor) |
| 110 *scale_factor = ui::SCALE_FACTOR_100P; | 109 *scale_factor = 1.0f; |
| 111 | 110 |
| 112 // Detect and parse resource string ending in @<scale>x. | 111 // Detect and parse resource string ending in @<scale>x. |
| 113 std::size_t pos = path->rfind('@'); | 112 std::size_t pos = path->rfind('@'); |
| 114 if (pos != std::string::npos) { | 113 if (pos != std::string::npos) { |
| 115 base::StringPiece stripped_path(*path); | 114 base::StringPiece stripped_path(*path); |
| 116 ui::ScaleFactor factor; | 115 float factor; |
| 117 | 116 |
| 118 if (ParseScaleFactor(stripped_path.substr( | 117 if (ParseScaleFactor(stripped_path.substr( |
| 119 pos + 1, stripped_path.length() - pos - 1), &factor)) { | 118 pos + 1, stripped_path.length() - pos - 1), &factor)) { |
| 120 // Strip scale factor specification from path. | 119 // Strip scale factor specification from path. |
| 121 stripped_path.remove_suffix(stripped_path.length() - pos); | 120 stripped_path.remove_suffix(stripped_path.length() - pos); |
| 122 stripped_path.CopyToString(path); | 121 stripped_path.CopyToString(path); |
| 123 } | 122 } |
| 124 if (scale_factor) | 123 if (scale_factor) |
| 125 *scale_factor = factor; | 124 *scale_factor = factor; |
| 126 } | 125 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 148 #endif | 147 #endif |
| 149 | 148 |
| 150 localized_strings->SetString("fontfamily", font_family); | 149 localized_strings->SetString("fontfamily", font_family); |
| 151 localized_strings->SetString("fontsize", | 150 localized_strings->SetString("fontsize", |
| 152 l10n_util::GetStringUTF8(web_font_size_id)); | 151 l10n_util::GetStringUTF8(web_font_size_id)); |
| 153 localized_strings->SetString("textdirection", | 152 localized_strings->SetString("textdirection", |
| 154 base::i18n::IsRTL() ? "rtl" : "ltr"); | 153 base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 155 } | 154 } |
| 156 | 155 |
| 157 } // namespace webui | 156 } // namespace webui |
| OLD | NEW |