| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 24d0a6d commit 0808057
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,8 @@ foreach(_f IN LISTS _all_cpp) | |||
| 10 | 10 | set(_skip FALSE) | |
| 11 | 11 | if(_name MATCHES "_win\\.cpp$" AND NOT WIN32) | |
| 12 | 12 | set(_skip TRUE) | |
| 13 | + elseif(_name STREQUAL "dpi_aware.cpp" AND NOT WIN32) | ||
| 14 | + set(_skip TRUE) | ||
| 13 | 15 | elseif(_name MATCHES "_linux\\.cpp$" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Linux") | |
| 14 | 16 | set(_skip TRUE) | |
| 15 | 17 | elseif(_name MATCHES "_mac\\.(cpp|mm)$" AND NOT APPLE) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,64 +30,44 @@ std::string GetPromptText(GtkDialog* dialog) { | |||
| 30 | 30 | return std::string(); | |
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | - std::string GetDescriptionFromMimeType(const std::string& mime_type) { | ||
| 34 | - // Check for wild card mime types and return an appropriate description. | ||
| 35 | - static const struct { | ||
| 36 | - const char* mime_type; | ||
| 37 | - const char* label; | ||
| 38 | - } kWildCardMimeTypes[] = { | ||
| 39 | - {"audio", "Audio Files"}, | ||
| 40 | - {"image", "Image Files"}, | ||
| 41 | - {"text", "Text Files"}, | ||
| 42 | - {"video", "Video Files"}, | ||
| 43 | - }; | ||
| 44 | - | ||
| 45 | - for (size_t i = 0; | ||
| 46 | - i < sizeof(kWildCardMimeTypes) / sizeof(kWildCardMimeTypes[0]); ++i) { | ||
| 47 | - if (mime_type == std::string(kWildCardMimeTypes[i].mime_type) + "/*") | ||
| 48 | - return std::string(kWildCardMimeTypes[i].label); | ||
| 33 | + // Split |str| on |delim| and return the parts. | ||
| 34 | + std::vector<std::string> SplitString(const std::string& str, char delim) { | ||
| 35 | + std::vector<std::string> result; | ||
| 36 | + std::string token; | ||
| 37 | + for (char c : str) { | ||
| 38 | + if (c == delim) { | ||
| 39 | + if (!token.empty()) | ||
| 40 | + result.push_back(token); | ||
| 41 | + token.clear(); | ||
| 42 | + } else { | ||
| 43 | + token += c; | ||
| 44 | + } | ||
| 49 | 45 | } | |
| 50 | - | ||
| 51 | - return std::string(); | ||
| 46 | + if (!token.empty()) | ||
| 47 | + result.push_back(token); | ||
| 48 | + return result; | ||
| 52 | 49 | } | |
| 53 | 50 | ||
| 54 | 51 | void AddFilters(GtkFileChooser* chooser, | |
| 55 | 52 | const std::vector<CefString>& accept_filters, | |
| 53 | + const std::vector<CefString>& accept_extensions, | ||
| 54 | + const std::vector<CefString>& accept_descriptions, | ||
| 56 | 55 | bool include_all_files, | |
| 57 | 56 | std::vector<GtkFileFilter*>* filters) { | |
| 58 | 57 | bool has_filter = false; | |
| 59 | 58 | ||
| 60 | - for (size_t i = 0; i < accept_filters.size(); ++i) { | ||
| 61 | - const std::string& filter = accept_filters[i]; | ||
| 59 | + for (size_t j = 0; j < accept_filters.size(); ++j) { | ||
| 60 | + const std::string& filter = accept_filters[j]; | ||
| 62 | 61 | if (filter.empty()) | |
| 63 | 62 | continue; | |
| 64 | 63 | ||
| 65 | - std::vector<std::string> extensions; | ||
| 66 | - std::string description; | ||
| 67 | - | ||
| 68 | - size_t sep_index = filter.find('|'); | ||
| 69 | - if (sep_index != std::string::npos) { | ||
| 70 | - // Treat as a filter of the form "Filter Name|.ext1;.ext2;.ext3". | ||
| 71 | - description = filter.substr(0, sep_index); | ||
| 72 | - | ||
| 73 | - const std::string& exts = filter.substr(sep_index + 1); | ||
| 74 | - size_t last = 0; | ||
| 75 | - size_t size = exts.size(); | ||
| 76 | - for (size_t i = 0; i <= size; ++i) { | ||
| 77 | - if (i == size || exts[i] == ';') { | ||
| 78 | - std::string ext(exts, last, i - last); | ||
| 79 | - if (!ext.empty() && ext[0] == '.') | ||
| 80 | - extensions.push_back(ext); | ||
| 81 | - last = i + 1; | ||
| 82 | - } | ||
| 83 | - } | ||
| 84 | - } else if (filter[0] == '.') { | ||
| 85 | - // Treat as an extension beginning with the '.' character. | ||
| 86 | - extensions.push_back(filter); | ||
| 87 | - } else { | ||
| 88 | - // Otherwise convert mime type to one or more extensions. | ||
| 89 | - description = GetDescriptionFromMimeType(filter); | ||
| 64 | + // Use pre-parsed extensions when available. | ||
| 65 | + std::vector<std::string> extensions = | ||
| 66 | + SplitString(accept_extensions[j], ';'); | ||
| 67 | + std::string description = accept_descriptions[j]; | ||
| 90 | 68 | ||
| 69 | + if (extensions.empty()) { | ||
| 70 | + // Fallback: convert MIME type to extensions. | ||
| 91 | 71 | std::vector<CefString> ext; | |
| 92 | 72 | CefGetExtensionsForMimeType(filter, ext); | |
| 93 | 73 | for (size_t x = 0; x < ext.size(); ++x) | |
@@ -101,7 +81,9 @@ void AddFilters(GtkFileChooser* chooser, | |||
| 101 | 81 | ||
| 102 | 82 | std::string ext_str; | |
| 103 | 83 | for (size_t x = 0; x < extensions.size(); ++x) { | |
| 104 | - const std::string& pattern = "*" + extensions[x]; | ||
| 84 | + std::string pattern = extensions[x]; | ||
| 85 | + if (pattern[0] != '*') | ||
| 86 | + pattern = "*" + pattern; | ||
| 105 | 87 | if (x != 0) | |
| 106 | 88 | ext_str += ";"; | |
| 107 | 89 | ext_str += pattern; | |
@@ -133,34 +115,31 @@ void AddFilters(GtkFileChooser* chooser, | |||
| 133 | 115 | ||
| 134 | 116 | } // namespace | |
| 135 | 117 | ||
| 136 | - ClientDialogHandlerGtk::ClientDialogHandlerGtk() : gtk_dialog_(NULL) {} | ||
| 118 | + ClientDialogHandlerGtk::ClientDialogHandlerGtk() : gtk_dialog_(nullptr) {} | ||
| 137 | 119 | ||
| 138 | 120 | bool ClientDialogHandlerGtk::OnFileDialog( | |
| 139 | 121 | CefRefPtr<CefBrowser> browser, | |
| 140 | 122 | FileDialogMode mode, | |
| 141 | 123 | const CefString& title, | |
| 142 | 124 | const CefString& default_file_path, | |
| 143 | 125 | const std::vector<CefString>& accept_filters, | |
| 144 | - int selected_accept_filter, | ||
| 126 | + const std::vector<CefString>& accept_extensions, | ||
| 127 | + const std::vector<CefString>& accept_descriptions, | ||
| 145 | 128 | CefRefPtr<CefFileDialogCallback> callback) { | |
| 146 | 129 | std::vector<CefString> files; | |
| 147 | 130 | ||
| 148 | 131 | GtkFileChooserAction action; | |
| 149 | 132 | const gchar* accept_button; | |
| 150 | 133 | ||
| 151 | - // Remove any modifier flags. | ||
| 152 | - FileDialogMode mode_type = | ||
| 153 | - static_cast<FileDialogMode>(mode & FILE_DIALOG_TYPE_MASK); | ||
| 154 | - | ||
| 155 | - if (mode_type == FILE_DIALOG_OPEN || mode_type == FILE_DIALOG_OPEN_MULTIPLE) { | ||
| 134 | + if (mode == FILE_DIALOG_OPEN || mode == FILE_DIALOG_OPEN_MULTIPLE) { | ||
| 156 | 135 | action = GTK_FILE_CHOOSER_ACTION_OPEN; | |
| 157 | - accept_button = GTK_STOCK_OPEN; | ||
| 158 | - } else if (mode_type == FILE_DIALOG_OPEN_FOLDER) { | ||
| 136 | + accept_button = "_Open"; | ||
| 137 | + } else if (mode == FILE_DIALOG_OPEN_FOLDER) { | ||
| 159 | 138 | action = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER; | |
| 160 | - accept_button = GTK_STOCK_OPEN; | ||
| 161 | - } else if (mode_type == FILE_DIALOG_SAVE) { | ||
| 139 | + accept_button = "_Open"; | ||
| 140 | + } else if (mode == FILE_DIALOG_SAVE) { | ||
| 162 | 141 | action = GTK_FILE_CHOOSER_ACTION_SAVE; | |
| 163 | - accept_button = GTK_STOCK_SAVE; | ||
| 142 | + accept_button = "_Save"; | ||
| 164 | 143 | } else { | |
| 165 | 144 | NOTREACHED(); | |
| 166 | 145 | return false; | |
@@ -170,7 +149,7 @@ bool ClientDialogHandlerGtk::OnFileDialog( | |||
| 170 | 149 | if (!title.empty()) { | |
| 171 | 150 | title_str = title; | |
| 172 | 151 | } else { | |
| 173 | - switch (mode_type) { | ||
| 152 | + switch (mode) { | ||
| 174 | 153 | case FILE_DIALOG_OPEN: | |
| 175 | 154 | title_str = "Open File"; | |
| 176 | 155 | break; | |
@@ -193,21 +172,13 @@ bool ClientDialogHandlerGtk::OnFileDialog( | |||
| 193 | 172 | return false; | |
| 194 | 173 | ||
| 195 | 174 | GtkWidget* dialog = gtk_file_chooser_dialog_new( | |
| 196 | - title_str.c_str(), GTK_WINDOW(window), action, GTK_STOCK_CANCEL, | ||
| 197 | - GTK_RESPONSE_CANCEL, accept_button, GTK_RESPONSE_ACCEPT, NULL); | ||
| 175 | + title_str.c_str(), GTK_WINDOW(window), action, "_Cancel", | ||
| 176 | + GTK_RESPONSE_CANCEL, accept_button, GTK_RESPONSE_ACCEPT, nullptr); | ||
| 198 | 177 | ||
| 199 | - if (mode_type == FILE_DIALOG_OPEN_MULTIPLE) | ||
| 178 | + if (mode == FILE_DIALOG_OPEN_MULTIPLE) | ||
| 200 | 179 | gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
| 201 | 180 | ||
| 202 | - if (mode_type == FILE_DIALOG_SAVE) { | ||
| 203 | - gtk_file_chooser_set_do_overwrite_confirmation( | ||
| 204 | - GTK_FILE_CHOOSER(dialog), !!(mode & FILE_DIALOG_OVERWRITEPROMPT_FLAG)); | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(dialog), | ||
| 208 | - !(mode & FILE_DIALOG_HIDEREADONLY_FLAG)); | ||
| 209 | - | ||
| 210 | - if (!default_file_path.empty() && mode_type == FILE_DIALOG_SAVE) { | ||
| 181 | + if (!default_file_path.empty() && mode == FILE_DIALOG_SAVE) { | ||
| 211 | 182 | const std::string& file_path = default_file_path; | |
| 212 | 183 | bool exists = false; | |
| 213 | 184 | ||
@@ -227,25 +198,22 @@ bool ClientDialogHandlerGtk::OnFileDialog( | |||
| 227 | 198 | } | |
| 228 | 199 | ||
| 229 | 200 | std::vector<GtkFileFilter*> filters; | |
| 230 | - AddFilters(GTK_FILE_CHOOSER(dialog), accept_filters, true, &filters); | ||
| 231 | - if (selected_accept_filter < static_cast<int>(filters.size())) { | ||
| 232 | - gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), | ||
| 233 | - filters[selected_accept_filter]); | ||
| 234 | - } | ||
| 201 | + AddFilters(GTK_FILE_CHOOSER(dialog), accept_filters, accept_extensions, | ||
| 202 | + accept_descriptions, true, &filters); | ||
| 235 | 203 | ||
| 236 | 204 | bool success = false; | |
| 237 | 205 | ||
| 238 | 206 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { | |
| 239 | - if (mode_type == FILE_DIALOG_OPEN || mode_type == FILE_DIALOG_OPEN_FOLDER || | ||
| 240 | - mode_type == FILE_DIALOG_SAVE) { | ||
| 207 | + if (mode == FILE_DIALOG_OPEN || mode == FILE_DIALOG_OPEN_FOLDER || | ||
| 208 | + mode == FILE_DIALOG_SAVE) { | ||
| 241 | 209 | char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
| 242 | 210 | files.push_back(std::string(filename)); | |
| 243 | 211 | success = true; | |
| 244 | - } else if (mode_type == FILE_DIALOG_OPEN_MULTIPLE) { | ||
| 212 | + } else if (mode == FILE_DIALOG_OPEN_MULTIPLE) { | ||
| 245 | 213 | GSList* filenames = | |
| 246 | 214 | gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); | |
| 247 | 215 | if (filenames) { | |
| 248 | - for (GSList* iter = filenames; iter != NULL; | ||
| 216 | + for (GSList* iter = filenames; iter != nullptr; | ||
| 249 | 217 | iter = g_slist_next(iter)) { | |
| 250 | 218 | std::string path(static_cast<char*>(iter->data)); | |
| 251 | 219 | g_free(iter->data); | |
@@ -257,24 +225,10 @@ bool ClientDialogHandlerGtk::OnFileDialog( | |||
| 257 | 225 | } | |
| 258 | 226 | } | |
| 259 | 227 | ||
| 260 | - int filter_index = selected_accept_filter; | ||
| 261 | - if (success) { | ||
| 262 | - GtkFileFilter* selected_filter = | ||
| 263 | - gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog)); | ||
| 264 | - if (selected_filter != NULL) { | ||
| 265 | - for (size_t x = 0; x < filters.size(); ++x) { | ||
| 266 | - if (filters[x] == selected_filter) { | ||
| 267 | - filter_index = x; | ||
| 268 | - break; | ||
| 269 | - } | ||
| 270 | - } | ||
| 271 | - } | ||
| 272 | - } | ||
| 273 | - | ||
| 274 | 228 | gtk_widget_destroy(dialog); | |
| 275 | 229 | ||
| 276 | 230 | if (success) | |
| 277 | - callback->Continue(filter_index, files); | ||
| 231 | + callback->Continue(files); | ||
| 278 | 232 | else | |
| 279 | 233 | callback->Cancel(); | |
| 280 | 234 | ||
@@ -316,11 +270,6 @@ bool ClientDialogHandlerGtk::OnJSDialog(CefRefPtr<CefBrowser> browser, | |||
| 316 | 270 | ||
| 317 | 271 | js_dialog_callback_ = callback; | |
| 318 | 272 | ||
| 319 | - if (!origin_url.empty()) { | ||
| 320 | - // title += " - "; | ||
| 321 | - // title += CefFormatUrlForSecurityDisplay(origin_url).ToString(); | ||
| 322 | - } | ||
| 323 | - | ||
| 324 | 273 | GtkWindow* window = CefBrowser_GetGtkWindow(browser); | |
| 325 | 274 | if (!window) | |
| 326 | 275 | return false; | |
@@ -329,12 +278,12 @@ bool ClientDialogHandlerGtk::OnJSDialog(CefRefPtr<CefBrowser> browser, | |||
| 329 | 278 | gtk_message_type, buttons, "%s", | |
| 330 | 279 | message_text.ToString().c_str()); | |
| 331 | 280 | g_signal_connect(gtk_dialog_, "delete-event", | |
| 332 | - G_CALLBACK(gtk_widget_hide_on_delete), NULL); | ||
| 281 | + G_CALLBACK(gtk_widget_hide_on_delete), nullptr); | ||
| 333 | 282 | ||
| 334 | 283 | gtk_window_set_title(GTK_WINDOW(gtk_dialog_), title.c_str()); | |
| 335 | 284 | ||
| 336 | 285 | GtkWidget* ok_button = gtk_dialog_add_button(GTK_DIALOG(gtk_dialog_), | |
| 337 | - GTK_STOCK_OK, GTK_RESPONSE_OK); | ||
| 286 | + "_OK", GTK_RESPONSE_OK); | ||
| 338 | 287 | ||
| 339 | 288 | if (dialog_type != JSDIALOGTYPE_PROMPT) | |
| 340 | 289 | gtk_widget_grab_focus(ok_button); | |
@@ -378,8 +327,8 @@ void ClientDialogHandlerGtk::OnResetDialogState(CefRefPtr<CefBrowser> browser) { | |||
| 378 | 327 | if (!gtk_dialog_) | |
| 379 | 328 | return; | |
| 380 | 329 | gtk_widget_destroy(gtk_dialog_); | |
| 381 | - gtk_dialog_ = NULL; | ||
| 382 | - js_dialog_callback_ = NULL; | ||
| 330 | + gtk_dialog_ = nullptr; | ||
| 331 | + js_dialog_callback_ = nullptr; | ||
| 383 | 332 | } | |
| 384 | 333 | ||
| 385 | 334 | // static | |
@@ -401,5 +350,5 @@ void ClientDialogHandlerGtk::OnDialogResponse(GtkDialog* dialog, | |||
| 401 | 350 | NOTREACHED(); | |
| 402 | 351 | } | |
| 403 | 352 | ||
| 404 | - handler->OnResetDialogState(NULL); | ||
| 353 | + handler->OnResetDialogState(nullptr); | ||
| 405 | 354 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,8 +25,9 @@ class ClientDialogHandlerGtk : public CefDialogHandler, | |||
| 25 | 25 | const CefString& title, | |
| 26 | 26 | const CefString& default_file_path, | |
| 27 | 27 | const std::vector<CefString>& accept_filters, | |
| 28 | - int selected_accept_filter, | ||
| 29 | - CefRefPtr<CefFileDialogCallback> callback) OVERRIDE; | ||
| 28 | + const std::vector<CefString>& accept_extensions, | ||
| 29 | + const std::vector<CefString>& accept_descriptions, | ||
| 30 | + CefRefPtr<CefFileDialogCallback> callback) override; | ||
| 30 | 31 | ||
| 31 | 32 | // CefJSDialogHandler methods. | |
| 32 | 33 | bool OnJSDialog(CefRefPtr<CefBrowser> browser, | |
@@ -35,12 +36,12 @@ class ClientDialogHandlerGtk : public CefDialogHandler, | |||
| 35 | 36 | const CefString& message_text, | |
| 36 | 37 | const CefString& default_prompt_text, | |
| 37 | 38 | CefRefPtr<CefJSDialogCallback> callback, | |
| 38 | - bool& suppress_message) OVERRIDE; | ||
| 39 | + bool& suppress_message) override; | ||
| 39 | 40 | bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> browser, | |
| 40 | 41 | const CefString& message_text, | |
| 41 | 42 | bool is_reload, | |
| 42 | - CefRefPtr<CefJSDialogCallback> callback) OVERRIDE; | ||
| 43 | - void OnResetDialogState(CefRefPtr<CefBrowser> browser) OVERRIDE; | ||
| 43 | + CefRefPtr<CefJSDialogCallback> callback) override; | ||
| 44 | + void OnResetDialogState(CefRefPtr<CefBrowser> browser) override; | ||
| 44 | 45 | ||
| 45 | 46 | private: | |
| 46 | 47 | static void OnDialogResponse(GtkDialog* dialog, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -599,7 +599,8 @@ void ClientPrintHandlerGtk::OnPrintReset(CefRefPtr<CefBrowser> browser) { | |||
| 599 | 599 | print_handler_map_.erase(it); | |
| 600 | 600 | } | |
| 601 | 601 | ||
| 602 | - CefSize ClientPrintHandlerGtk::GetPdfPaperSize(int device_units_per_inch) { | ||
| 602 | + CefSize ClientPrintHandlerGtk::GetPdfPaperSize(CefRefPtr<CefBrowser> browser, | ||
| 603 | + int device_units_per_inch) { | ||
| 603 | 604 | CEF_REQUIRE_UI_THREAD(); | |
| 604 | 605 | ||
| 605 | 606 | GtkPageSetup* page_setup = gtk_page_setup_new(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,19 +20,20 @@ class ClientPrintHandlerGtk : public CefPrintHandler { | |||
| 20 | 20 | virtual ~ClientPrintHandlerGtk(); | |
| 21 | 21 | ||
| 22 | 22 | // CefPrintHandler methods. | |
| 23 | - void OnPrintStart(CefRefPtr<CefBrowser> browser) OVERRIDE; | ||
| 23 | + void OnPrintStart(CefRefPtr<CefBrowser> browser) override; | ||
| 24 | 24 | void OnPrintSettings(CefRefPtr<CefBrowser> browser, | |
| 25 | 25 | CefRefPtr<CefPrintSettings> settings, | |
| 26 | - bool get_defaults) OVERRIDE; | ||
| 26 | + bool get_defaults) override; | ||
| 27 | 27 | bool OnPrintDialog(CefRefPtr<CefBrowser> browser, | |
| 28 | 28 | bool has_selection, | |
| 29 | - CefRefPtr<CefPrintDialogCallback> callback) OVERRIDE; | ||
| 29 | + CefRefPtr<CefPrintDialogCallback> callback) override; | ||
| 30 | 30 | bool OnPrintJob(CefRefPtr<CefBrowser> browser, | |
| 31 | 31 | const CefString& document_name, | |
| 32 | 32 | const CefString& pdf_file_path, | |
| 33 | - CefRefPtr<CefPrintJobCallback> callback) OVERRIDE; | ||
| 34 | - void OnPrintReset(CefRefPtr<CefBrowser> browser) OVERRIDE; | ||
| 35 | - CefSize GetPdfPaperSize(int device_units_per_inch) OVERRIDE; | ||
| 33 | + CefRefPtr<CefPrintJobCallback> callback) override; | ||
| 34 | + void OnPrintReset(CefRefPtr<CefBrowser> browser) override; | ||
| 35 | + CefSize GetPdfPaperSize(CefRefPtr<CefBrowser> browser, | ||
| 36 | + int device_units_per_inch) override; | ||
| 36 | 37 | ||
| 37 | 38 | private: | |
| 38 | 39 | // Print handler. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments