From c30a6232df03e1efbd9f3b226777b07e087a1122 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 12 Oct 2020 14:27:29 +0200 Subject: BASELINE: Update Chromium to 85.0.4183.140 Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen --- chromium/ui/base/BUILD.gn | 133 +-- chromium/ui/base/DEPS | 1 + chromium/ui/base/accelerators/accelerator.cc | 25 +- chromium/ui/base/accelerators/accelerator.h | 9 +- .../ui/base/accelerators/accelerator_history.h | 4 +- .../ui/base/accelerators/accelerator_manager.h | 4 +- .../accelerators/global_media_keys_listener_win.h | 5 +- .../ui/base/accelerators/media_keys_listener.h | 6 +- .../base/accelerators/media_keys_listener_mac.mm | 1 + chromium/ui/base/accelerators/media_keys_util.h | 9 +- .../accelerators/menu_label_accelerator_util.h | 8 +- .../menu_label_accelerator_util_linux.h | 10 +- .../base/accelerators/platform_accelerator_cocoa.h | 5 +- .../system_media_controls_media_keys_listener.h | 4 +- chromium/ui/base/base_window.h | 3 +- chromium/ui/base/class_property.h | 6 +- chromium/ui/base/clipboard/BUILD.gn | 72 +- chromium/ui/base/clipboard/clipboard.cc | 6 + chromium/ui/base/clipboard/clipboard.h | 11 + chromium/ui/base/clipboard/clipboard_android.cc | 11 +- chromium/ui/base/clipboard/clipboard_aura.cc | 626 ------------ chromium/ui/base/clipboard/clipboard_aura.h | 80 -- chromium/ui/base/clipboard/clipboard_constants.h | 7 + .../ui/base/clipboard/clipboard_constants_mac.mm | 5 + chromium/ui/base/clipboard/clipboard_linux.cc | 33 + chromium/ui/base/clipboard/clipboard_mac.h | 2 + chromium/ui/base/clipboard/clipboard_mac.mm | 30 + chromium/ui/base/clipboard/clipboard_metrics.cc | 20 + chromium/ui/base/clipboard/clipboard_metrics.h | 30 + chromium/ui/base/clipboard/clipboard_non_backed.cc | 636 ++++++++++++ chromium/ui/base/clipboard/clipboard_non_backed.h | 86 ++ chromium/ui/base/clipboard/clipboard_ozone.cc | 22 +- .../ui/base/clipboard/clipboard_test_template.h | 80 +- chromium/ui/base/clipboard/clipboard_util_mac.mm | 1 + chromium/ui/base/clipboard/clipboard_win.cc | 9 + chromium/ui/base/clipboard/clipboard_x11.cc | 337 +++---- .../ui/base/clipboard/scoped_clipboard_writer.cc | 16 + .../ui/base/clipboard/scoped_clipboard_writer.h | 5 + .../ui/base/cocoa/accessibility_focus_overrider.h | 4 +- chromium/ui/base/cocoa/appkit_utils.h | 6 +- chromium/ui/base/cocoa/base_view.h | 8 +- chromium/ui/base/cocoa/base_view.mm | 1 + chromium/ui/base/cocoa/bubble_closer.h | 4 +- chromium/ui/base/cocoa/cocoa_base_utils.h | 20 +- chromium/ui/base/cocoa/command_dispatcher.h | 4 +- chromium/ui/base/cocoa/command_dispatcher.mm | 49 +- .../constrained_window_animation.h | 10 +- .../constrained_window_animation.mm | 1 + chromium/ui/base/cocoa/controls/button_utils.h | 4 +- chromium/ui/base/cocoa/controls/textfield_utils.h | 4 +- chromium/ui/base/cocoa/defaults_utils.h | 6 +- chromium/ui/base/cocoa/find_pasteboard.h | 8 +- chromium/ui/base/cocoa/flipped_view.h | 4 +- chromium/ui/base/cocoa/focus_tracker.h | 4 +- chromium/ui/base/cocoa/focus_window_set.h | 9 +- chromium/ui/base/cocoa/focus_window_set.mm | 1 + chromium/ui/base/cocoa/menu_controller.h | 4 +- chromium/ui/base/cocoa/permissions_utils.h | 4 +- chromium/ui/base/cocoa/quartz_util.h | 6 +- chromium/ui/base/cocoa/remote_accessibility_api.h | 4 +- chromium/ui/base/cocoa/remote_layer_api.h | 4 +- chromium/ui/base/cocoa/secure_password_input.h | 4 +- .../ui/base/cocoa/text_services_context_menu.cc | 22 +- .../ui/base/cocoa/text_services_context_menu.h | 22 +- chromium/ui/base/cocoa/tool_tip_base_view.h | 3 +- chromium/ui/base/cocoa/touch_bar_util.h | 21 +- chromium/ui/base/cocoa/tracking_area.h | 6 +- .../ui/base/cocoa/underlay_opengl_hosting_window.h | 4 +- chromium/ui/base/cocoa/views_hostable.h | 2 +- chromium/ui/base/cocoa/weak_ptr_nsobject.h | 4 +- chromium/ui/base/cocoa/window_size_constants.h | 4 +- chromium/ui/base/cursor/BUILD.gn | 114 ++- chromium/ui/base/cursor/DEPS | 3 - chromium/ui/base/cursor/cursor.h | 4 +- chromium/ui/base/cursor/cursor_factory.cc | 68 ++ chromium/ui/base/cursor/cursor_factory.h | 67 ++ chromium/ui/base/cursor/cursor_loader.h | 11 +- chromium/ui/base/cursor/cursor_loader_ozone.cc | 65 +- chromium/ui/base/cursor/cursor_loader_ozone.h | 13 +- chromium/ui/base/cursor/cursor_loader_win.cc | 2 +- chromium/ui/base/cursor/cursor_loader_win.h | 5 +- chromium/ui/base/cursor/cursor_loader_x11.cc | 310 ------ chromium/ui/base/cursor/cursor_loader_x11.h | 93 -- chromium/ui/base/cursor/cursor_lookup.h | 8 +- chromium/ui/base/cursor/cursor_ozone.cc | 6 +- chromium/ui/base/cursor/cursor_theme_manager.cc | 47 + chromium/ui/base/cursor/cursor_theme_manager.h | 46 + .../ui/base/cursor/cursor_theme_manager_linux.cc | 42 - .../ui/base/cursor/cursor_theme_manager_linux.h | 52 - .../cursor/cursor_theme_manager_linux_observer.h | 31 - .../ui/base/cursor/cursor_theme_manager_observer.h | 29 + chromium/ui/base/cursor/cursor_unittest.cc | 23 +- chromium/ui/base/cursor/cursor_util.cc | 3 + chromium/ui/base/cursor/cursor_util.h | 21 +- chromium/ui/base/cursor/cursor_util_unittest.cc | 1 + chromium/ui/base/cursor/cursor_x11.cc | 21 - chromium/ui/base/cursor/cursors_aura.cc | 116 +-- chromium/ui/base/cursor/cursors_aura.h | 29 +- chromium/ui/base/cursor/image_cursors.cc | 72 +- chromium/ui/base/cursor/image_cursors.h | 23 +- chromium/ui/base/cursor/mojom/BUILD.gn | 4 +- .../cursor/mojom/cursor_mojom_traits_unittest.cc | 15 +- .../cursor/ozone/bitmap_cursor_factory_ozone.cc | 49 +- .../cursor/ozone/bitmap_cursor_factory_ozone.h | 31 +- chromium/ui/base/device_form_factor.h | 4 +- chromium/ui/base/dragdrop/cocoa_dnd_util.h | 15 +- chromium/ui/base/dragdrop/drag_drop_types.h | 4 +- chromium/ui/base/dragdrop/drag_source_win.cc | 2 +- chromium/ui/base/dragdrop/drag_source_win.h | 5 +- chromium/ui/base/dragdrop/drop_target_event.h | 3 +- chromium/ui/base/dragdrop/drop_target_win.h | 4 +- chromium/ui/base/dragdrop/os_exchange_data.cc | 2 +- chromium/ui/base/dragdrop/os_exchange_data.h | 4 +- .../ui/base/dragdrop/os_exchange_data_provider.h | 3 +- .../dragdrop/os_exchange_data_provider_aura.cc | 218 ---- .../base/dragdrop/os_exchange_data_provider_aura.h | 101 -- .../dragdrop/os_exchange_data_provider_factory.cc | 4 +- .../dragdrop/os_exchange_data_provider_factory.h | 4 +- .../base/dragdrop/os_exchange_data_provider_mac.h | 4 +- .../base/dragdrop/os_exchange_data_provider_mac.mm | 6 +- .../os_exchange_data_provider_non_backed.cc | 225 +++++ .../os_exchange_data_provider_non_backed.h | 107 ++ .../base/dragdrop/os_exchange_data_provider_win.cc | 10 +- .../base/dragdrop/os_exchange_data_provider_win.h | 5 +- .../base/dragdrop/os_exchange_data_provider_x11.cc | 8 +- .../base/dragdrop/os_exchange_data_provider_x11.h | 12 +- .../os_exchange_data_provider_x11_unittest.cc | 26 +- .../ui/base/dragdrop/os_exchange_data_unittest.cc | 35 +- .../base/dragdrop/os_exchange_data_win_unittest.cc | 15 +- chromium/ui/base/emoji/emoji_panel_helper.h | 10 +- chromium/ui/base/idle/BUILD.gn | 1 - chromium/ui/base/idle/idle_query_x11.cc | 41 +- chromium/ui/base/idle/idle_query_x11.h | 8 +- .../ui/base/idle/screensaver_window_finder_x11.cc | 34 +- .../ui/base/idle/screensaver_window_finder_x11.h | 4 +- chromium/ui/base/ime/BUILD.gn | 3 - chromium/ui/base/ime/chromeos/BUILD.gn | 2 + chromium/ui/base/ime/dummy_input_method.cc | 5 - chromium/ui/base/ime/dummy_input_method.h | 4 - chromium/ui/base/ime/dummy_text_input_client.cc | 8 + chromium/ui/base/ime/dummy_text_input_client.h | 6 + .../ui/base/ime/fuchsia/input_method_fuchsia.cc | 4 +- .../input_method_keyboard_controller_fuchsia.cc | 6 +- .../ime/ime_assistive_window_handler_interface.h | 23 +- chromium/ui/base/ime/ime_bridge.cc | 146 --- chromium/ui/base/ime/ime_bridge.h | 102 -- .../ui/base/ime/ime_engine_handler_interface.h | 15 + .../base/ime/ime_input_context_handler_interface.h | 5 + chromium/ui/base/ime/ime_text_span.h | 7 +- chromium/ui/base/ime/init/BUILD.gn | 3 + chromium/ui/base/ime/init/input_method_factory.cc | 28 +- .../ui/base/ime/init/input_method_initializer.cc | 6 +- chromium/ui/base/ime/input_method.h | 16 - chromium/ui/base/ime/input_method_base.cc | 32 +- chromium/ui/base/ime/input_method_base.h | 11 +- chromium/ui/base/ime/linux/BUILD.gn | 9 +- .../ui/base/ime/linux/input_method_auralinux.cc | 60 -- .../ui/base/ime/linux/input_method_auralinux.h | 12 - .../ime/linux/input_method_auralinux_unittest.cc | 22 +- .../ui/base/ime/mock_ime_input_context_handler.cc | 16 +- .../ui/base/ime/mock_ime_input_context_handler.h | 12 +- chromium/ui/base/ime/mock_input_method.cc | 10 +- chromium/ui/base/ime/mock_input_method.h | 4 - chromium/ui/base/ime/mojom/BUILD.gn | 41 +- chromium/ui/base/ime/mojom/ime_types.mojom | 25 + .../ui/base/ime/mojom/ime_types_mojom_traits.cc | 99 ++ .../ui/base/ime/mojom/ime_types_mojom_traits.h | 41 +- chromium/ui/base/ime/mojom/text_input_state.mojom | 68 ++ .../ui/base/ime/mojom/virtual_keyboard_types.mojom | 20 + chromium/ui/base/ime/text_input_client.h | 7 + .../base/ime/virtual_keyboard_visibility_request.h | 21 - chromium/ui/base/ime/win/input_method_win_base.cc | 61 -- chromium/ui/base/ime/win/input_method_win_base.h | 13 - chromium/ui/base/ime/win/input_method_win_imm32.cc | 19 +- chromium/ui/base/ime/win/input_method_win_tsf.cc | 5 - ...n_screen_keyboard_display_manager_input_pane.cc | 12 +- ...on_screen_keyboard_display_manager_input_pane.h | 10 +- .../on_screen_keyboard_display_manager_tab_tip.h | 1 - chromium/ui/base/ime/win/tsf_bridge.cc | 37 +- chromium/ui/base/ime/win/tsf_text_store.cc | 27 +- chromium/ui/base/ime/win/tsf_text_store.h | 9 + .../ui/base/ime/win/tsf_text_store_unittest.cc | 87 ++ chromium/ui/base/l10n/formatter.cc | 4 +- chromium/ui/base/l10n/formatter.h | 9 +- chromium/ui/base/l10n/l10n_font_util.h | 19 +- chromium/ui/base/l10n/l10n_util.cc | 1 + chromium/ui/base/l10n/l10n_util.h | 192 ++-- chromium/ui/base/l10n/l10n_util_android.h | 10 +- chromium/ui/base/l10n/l10n_util_collator.h | 5 +- chromium/ui/base/l10n/l10n_util_mac.h | 105 +- chromium/ui/base/l10n/l10n_util_win.h | 18 +- chromium/ui/base/l10n/time_format.cc | 5 +- chromium/ui/base/l10n/time_format.h | 4 +- chromium/ui/base/layout.cc | 12 +- chromium/ui/base/layout.h | 19 +- chromium/ui/base/models/button_menu_item_model.h | 6 +- chromium/ui/base/models/combobox_model.cc | 20 +- chromium/ui/base/models/combobox_model.h | 25 +- chromium/ui/base/models/combobox_model_observer.h | 5 +- chromium/ui/base/models/image_model.cc | 8 + chromium/ui/base/models/image_model.h | 7 +- chromium/ui/base/models/image_model_unittest.cc | 8 + chromium/ui/base/models/list_model.h | 2 +- chromium/ui/base/models/list_model_observer.h | 4 +- chromium/ui/base/models/list_selection_model.h | 4 +- chromium/ui/base/models/menu_model.cc | 12 + chromium/ui/base/models/menu_model.h | 18 +- chromium/ui/base/models/simple_combobox_model.cc | 4 +- chromium/ui/base/models/simple_combobox_model.h | 7 +- chromium/ui/base/models/simple_menu_model.cc | 20 + chromium/ui/base/models/simple_menu_model.h | 15 +- .../ui/base/models/simple_menu_model_unittest.cc | 32 + chromium/ui/base/models/table_model.h | 6 +- chromium/ui/base/models/table_model_observer.h | 4 +- chromium/ui/base/models/tree_model.h | 6 +- chromium/ui/base/models/tree_node_iterator.h | 2 +- chromium/ui/base/models/tree_node_model.h | 2 +- chromium/ui/base/mojom/BUILD.gn | 9 + chromium/ui/base/mojom/attributed_string.mojom | 32 + .../mojom/window_open_disposition_mojom_traits.h | 2 +- chromium/ui/base/nine_image_painter_factory.h | 5 +- chromium/ui/base/page_transition_types.h | 36 +- chromium/ui/base/pointer/pointer_device.h | 22 +- .../ui/base/pointer/touch_editing_controller.h | 15 +- chromium/ui/base/pointer/touch_ui_controller.cc | 48 +- chromium/ui/base/pointer/touch_ui_controller.h | 14 +- chromium/ui/base/resource/data_pack.cc | 23 +- chromium/ui/base/resource/resource_bundle.cc | 53 +- chromium/ui/base/resource/resource_bundle.h | 24 +- .../ui/base/resource/resource_bundle_android.cc | 38 +- .../ui/base/resource/resource_bundle_android.h | 42 +- chromium/ui/base/resource/resource_bundle_ios.mm | 11 +- chromium/ui/base/resource/resource_bundle_mac.mm | 12 +- .../ui/base/resource/resource_bundle_unittest.cc | 8 +- chromium/ui/base/resource/resource_bundle_win.h | 6 +- chromium/ui/base/scoped_visibility_tracker.h | 4 +- chromium/ui/base/template_expressions.cc | 2 + chromium/ui/base/template_expressions.h | 16 +- chromium/ui/base/text/bytes_formatting.h | 15 +- chromium/ui/base/theme_provider.h | 4 +- chromium/ui/base/ui_base_export.h | 37 - chromium/ui/base/ui_base_features.cc | 44 +- chromium/ui/base/ui_base_features.h | 23 +- chromium/ui/base/ui_base_paths.h | 4 +- chromium/ui/base/ui_base_switches.h | 52 +- chromium/ui/base/ui_base_switches_util.h | 4 +- chromium/ui/base/ui_base_types.h | 5 +- .../ui/base/user_activity/user_activity_detector.h | 5 +- .../ui/base/user_activity/user_activity_observer.h | 4 +- chromium/ui/base/view_prop.cc | 4 +- chromium/ui/base/view_prop.h | 4 +- chromium/ui/base/webui/i18n_source_stream.h | 5 +- chromium/ui/base/webui/jstemplate_builder.cc | 2 +- chromium/ui/base/webui/jstemplate_builder.h | 23 +- chromium/ui/base/webui/web_ui_util.cc | 8 - chromium/ui/base/webui/web_ui_util.h | 61 +- chromium/ui/base/win/accessibility_misc_utils.h | 4 +- chromium/ui/base/win/event_creation_utils.cc | 37 + chromium/ui/base/win/event_creation_utils.h | 23 + chromium/ui/base/win/foreground_helper.h | 6 +- chromium/ui/base/win/hidden_window.cc | 1 + chromium/ui/base/win/hidden_window.h | 4 +- chromium/ui/base/win/hwnd_metrics.h | 4 +- chromium/ui/base/win/hwnd_subclass.h | 6 +- chromium/ui/base/win/internal_constants.h | 7 +- chromium/ui/base/win/lock_state.h | 4 +- chromium/ui/base/win/message_box_win.h | 11 +- chromium/ui/base/win/mouse_wheel_util.h | 10 +- chromium/ui/base/win/scoped_ole_initializer.h | 4 +- chromium/ui/base/win/session_change_observer.h | 4 +- chromium/ui/base/win/shell.h | 48 +- chromium/ui/base/win/touch_input.h | 11 +- chromium/ui/base/win/window_event_target.h | 4 +- chromium/ui/base/window_open_disposition.h | 28 +- chromium/ui/base/x/BUILD.gn | 25 +- chromium/ui/base/x/selection_owner.cc | 233 ++--- chromium/ui/base/x/selection_owner.h | 42 +- chromium/ui/base/x/selection_requestor.cc | 172 ++-- chromium/ui/base/x/selection_requestor.h | 52 +- chromium/ui/base/x/selection_requestor_unittest.cc | 86 +- chromium/ui/base/x/selection_utils.cc | 53 +- chromium/ui/base/x/selection_utils.h | 32 +- chromium/ui/base/x/x11_cursor.cc | 48 + chromium/ui/base/x/x11_cursor.h | 55 ++ chromium/ui/base/x/x11_cursor_factory.cc | 118 +++ chromium/ui/base/x/x11_cursor_factory.h | 67 ++ chromium/ui/base/x/x11_cursor_factory_unittest.cc | 32 + chromium/ui/base/x/x11_display_manager.cc | 56 +- chromium/ui/base/x/x11_display_manager.h | 11 +- chromium/ui/base/x/x11_display_util.cc | 381 ++++--- chromium/ui/base/x/x11_display_util.h | 4 +- chromium/ui/base/x/x11_drag_context.cc | 71 +- chromium/ui/base/x/x11_drag_context.h | 36 +- chromium/ui/base/x/x11_drag_drop_client.cc | 285 +++--- chromium/ui/base/x/x11_drag_drop_client.h | 61 +- chromium/ui/base/x/x11_error_handler.cc | 104 ++ chromium/ui/base/x/x11_error_handler.h | 26 + chromium/ui/base/x/x11_gl_egl_utility.cc | 14 +- chromium/ui/base/x/x11_menu_list.cc | 8 +- chromium/ui/base/x/x11_menu_list.h | 15 +- chromium/ui/base/x/x11_menu_registrar.cc | 15 +- chromium/ui/base/x/x11_menu_registrar.h | 7 +- .../ui/base/x/x11_os_exchange_data_provider.cc | 84 +- chromium/ui/base/x/x11_os_exchange_data_provider.h | 17 +- chromium/ui/base/x/x11_pointer_grab.cc | 21 +- chromium/ui/base/x/x11_pointer_grab.h | 2 +- chromium/ui/base/x/x11_shm_image_pool.cc | 20 +- chromium/ui/base/x/x11_shm_image_pool.h | 9 +- .../ui/base/x/x11_software_bitmap_presenter.cc | 62 +- chromium/ui/base/x/x11_software_bitmap_presenter.h | 2 +- chromium/ui/base/x/x11_topmost_window_finder.h | 2 +- chromium/ui/base/x/x11_util.cc | 1011 ++++++++++--------- chromium/ui/base/x/x11_util.h | 311 +++++- chromium/ui/base/x/x11_util_internal.h | 49 +- chromium/ui/base/x/x11_whole_screen_move_loop.cc | 79 +- chromium/ui/base/x/x11_whole_screen_move_loop.h | 4 +- chromium/ui/base/x/x11_window.cc | 1043 ++++++++++---------- chromium/ui/base/x/x11_window.h | 66 +- chromium/ui/base/x/x11_workspace_handler.cc | 19 +- chromium/ui/base/x/x11_workspace_handler.h | 7 +- chromium/ui/base/x/xwmstartupcheck/BUILD.gn | 13 + .../ui/base/x/xwmstartupcheck/xwmstartupcheck.cc | 125 +++ 322 files changed, 6904 insertions(+), 5860 deletions(-) delete mode 100644 chromium/ui/base/clipboard/clipboard_aura.cc delete mode 100644 chromium/ui/base/clipboard/clipboard_aura.h create mode 100644 chromium/ui/base/clipboard/clipboard_linux.cc create mode 100644 chromium/ui/base/clipboard/clipboard_metrics.cc create mode 100644 chromium/ui/base/clipboard/clipboard_metrics.h create mode 100644 chromium/ui/base/clipboard/clipboard_non_backed.cc create mode 100644 chromium/ui/base/clipboard/clipboard_non_backed.h delete mode 100644 chromium/ui/base/cursor/DEPS create mode 100644 chromium/ui/base/cursor/cursor_factory.cc create mode 100644 chromium/ui/base/cursor/cursor_factory.h delete mode 100644 chromium/ui/base/cursor/cursor_loader_x11.cc delete mode 100644 chromium/ui/base/cursor/cursor_loader_x11.h create mode 100644 chromium/ui/base/cursor/cursor_theme_manager.cc create mode 100644 chromium/ui/base/cursor/cursor_theme_manager.h delete mode 100644 chromium/ui/base/cursor/cursor_theme_manager_linux.cc delete mode 100644 chromium/ui/base/cursor/cursor_theme_manager_linux.h delete mode 100644 chromium/ui/base/cursor/cursor_theme_manager_linux_observer.h create mode 100644 chromium/ui/base/cursor/cursor_theme_manager_observer.h delete mode 100644 chromium/ui/base/cursor/cursor_x11.cc delete mode 100644 chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc delete mode 100644 chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h create mode 100644 chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc create mode 100644 chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h delete mode 100644 chromium/ui/base/ime/ime_bridge.cc delete mode 100644 chromium/ui/base/ime/ime_bridge.h create mode 100644 chromium/ui/base/ime/mojom/text_input_state.mojom create mode 100644 chromium/ui/base/ime/mojom/virtual_keyboard_types.mojom delete mode 100644 chromium/ui/base/ime/virtual_keyboard_visibility_request.h create mode 100644 chromium/ui/base/mojom/attributed_string.mojom delete mode 100644 chromium/ui/base/ui_base_export.h create mode 100644 chromium/ui/base/win/event_creation_utils.cc create mode 100644 chromium/ui/base/win/event_creation_utils.h create mode 100644 chromium/ui/base/x/x11_cursor.cc create mode 100644 chromium/ui/base/x/x11_cursor.h create mode 100644 chromium/ui/base/x/x11_cursor_factory.cc create mode 100644 chromium/ui/base/x/x11_cursor_factory.h create mode 100644 chromium/ui/base/x/x11_cursor_factory_unittest.cc create mode 100644 chromium/ui/base/x/x11_error_handler.cc create mode 100644 chromium/ui/base/x/x11_error_handler.h create mode 100644 chromium/ui/base/x/xwmstartupcheck/BUILD.gn create mode 100644 chromium/ui/base/x/xwmstartupcheck/xwmstartupcheck.cc (limited to 'chromium/ui/base') diff --git a/chromium/ui/base/BUILD.gn b/chromium/ui/base/BUILD.gn index 547ecab34e4..1179753aeff 100644 --- a/chromium/ui/base/BUILD.gn +++ b/chromium/ui/base/BUILD.gn @@ -3,6 +3,7 @@ # found in the LICENSE file. import("//build/buildflag_header.gni") +import("//build/config/chromeos/ui_mode.gni") import("//build/config/compiler/compiler.gni") import("//build/config/dcheck_always_on.gni") import("//build/config/jumbo.gni") @@ -66,6 +67,7 @@ buildflag_header("buildflags") { flags = [ "ENABLE_HIDPI=$enable_hidpi", "ENABLE_MESSAGE_CENTER=$enable_message_center", + "LACROS=$chromeos_is_browser_only", "USE_ATK=$use_atk", "USE_XKBCOMMON=$use_xkbcommon", "HAS_NATIVE_ACCESSIBILITY=$has_native_accessibility", @@ -93,9 +95,6 @@ jumbo_component("base") { sources = [ "class_property.cc", "class_property.h", - "cursor/cursor_loader.h", - "cursor/cursor_lookup.cc", - "cursor/cursor_lookup.h", "default_style.h", "device_form_factor.h", "device_form_factor_desktop.cc", @@ -158,7 +157,6 @@ jumbo_component("base") { "template_expressions.h", "theme_provider.cc", "theme_provider.h", - "ui_base_export.h", "ui_base_exports.cc", "ui_base_paths.cc", "ui_base_paths.h", @@ -178,6 +176,8 @@ jumbo_component("base") { "window_open_disposition.h", ] + libs = [] + if (is_android) { sources += [ "device_form_factor_android.cc", @@ -207,6 +207,8 @@ jumbo_component("base") { "win/accessibility_misc_utils.cc", "win/accessibility_misc_utils.h", "win/atl_module.h", + "win/event_creation_utils.cc", + "win/event_creation_utils.h", "win/foreground_helper.cc", "win/foreground_helper.h", "win/hidden_window.cc", @@ -234,6 +236,11 @@ jumbo_component("base") { "win/window_event_target.cc", "win/window_event_target.h", ] + ldflags = [ "/DELAYLOAD:dwmapi.dll" ] + libs += [ + "dwmapi.lib", + "wtsapi32.lib", + ] } if (is_mac) { @@ -333,8 +340,6 @@ jumbo_component("base") { "accelerators/system_media_controls_media_keys_listener.h", "base_window.cc", "base_window.h", - "cursor/cursor_util.cc", - "cursor/cursor_util.h", "emoji/emoji_panel_helper.h", "pointer/pointer_device.h", "pointer/pointer_device_util.cc", @@ -416,7 +421,7 @@ jumbo_component("base") { configs += [ "//build/config/compiler:wexit_time_destructors" ] - defines = [ "UI_BASE_IMPLEMENTATION" ] + defines = [ "IS_UI_BASE_IMPL" ] public_deps = [ ":buildflags", @@ -425,11 +430,10 @@ jumbo_component("base") { ":ui_data_pack", "//base", "//skia", - "//ui/base/cursor", - "//ui/base/cursor/mojom:cursor_type", "//ui/gfx", "//ui/gfx/geometry", ] + deps = [ "//base:base_static", "//base:i18n", @@ -445,7 +449,7 @@ jumbo_component("base") { "//ui/display", "//ui/events", "//ui/events/devices", - "//ui/resources", + "//ui/resources:webui_resources_grd", "//ui/strings", "//url", ] @@ -479,7 +483,7 @@ jumbo_component("base") { deps += [ "//ui/events" ] } - if (is_desktop_linux && (use_x11 || ozone_platform_x11)) { + if ((is_desktop_linux || is_chromeos) && (use_x11 || ozone_platform_x11)) { public_deps += [ "//ui/base/x" ] # X11 drag and drop wants to use common drag and drop types. @@ -494,8 +498,6 @@ jumbo_component("base") { if (use_x11 && use_aura) { sources += [ - "cursor/cursor_loader_x11.cc", - "cursor/cursor_loader_x11.h", "x/selection_requestor.cc", "x/selection_requestor.h", ] @@ -521,14 +523,6 @@ jumbo_component("base") { deps += [ "//third_party/fontconfig" ] } - if (is_desktop_linux) { - sources += [ - "cursor/cursor_theme_manager_linux.cc", - "cursor/cursor_theme_manager_linux.h", - "cursor/cursor_theme_manager_linux_observer.h", - ] - } - if (use_glib) { configs += [ "//build/config/linux:glib" ] sources += [ @@ -540,8 +534,8 @@ jumbo_component("base") { if (is_chromeos || (use_aura && is_linux && !use_x11)) { sources += [ - "dragdrop/os_exchange_data_provider_aura.cc", - "dragdrop/os_exchange_data_provider_aura.h", + "dragdrop/os_exchange_data_provider_non_backed.cc", + "dragdrop/os_exchange_data_provider_non_backed.h", ] } @@ -549,37 +543,11 @@ jumbo_component("base") { deps += [ "//ui/base/clipboard" ] } - libs = [] - if (is_win) { - sources += [ - "cursor/cursor_loader_win.cc", - "cursor/cursor_loader_win.h", - ] - deps += [ "//third_party/wtl" ] - cflags = [ "/wd4324" ] # Structure was padded due to __declspec(align()), - # which is uninteresting. - - ldflags = [ - "/DELAYLOAD:d2d1.dll", - "/DELAYLOAD:d3d10_1.dll", - "/DELAYLOAD:dwmapi.dll", - ] - libs += [ - "d2d1.lib", - "d3d10_1.lib", - "dwmapi.lib", - "d2d1.lib", - "dwmapi.lib", - "oleacc.lib", - "wtsapi32.lib", + if (!use_aura) { + sources -= [ + "view_prop.cc", + "view_prop.h", ] - } else { - if (!use_aura) { - sources -= [ - "view_prop.cc", - "view_prop.h", - ] - } } if (is_mac) { @@ -596,20 +564,6 @@ jumbo_component("base") { ] } - if (use_ozone) { - sources += [ - "cursor/cursor_loader_ozone.cc", - "cursor/cursor_loader_ozone.h", - "cursor/ozone/bitmap_cursor_factory_ozone.cc", - "cursor/ozone/bitmap_cursor_factory_ozone.h", - ] - - deps += [ - "//ui/events/ozone/layout", - "//ui/ozone:ozone_base", - ] - } - if (!toolkit_views && !use_aura) { sources -= [ "dragdrop/drag_drop_types.h", @@ -637,16 +591,6 @@ jumbo_component("base") { ] } - if (use_aura) { - # Cursor - sources += [ - "cursor/cursors_aura.cc", - "cursor/cursors_aura.h", - "cursor/image_cursors.cc", - "cursor/image_cursors.h", - ] - } - if (is_android || is_ios) { sources -= [ "device_form_factor_desktop.cc" ] } @@ -690,10 +634,13 @@ component("features") { ] } +# TODO(crbug.com/1091985): Support CrOS. if (is_win || is_mac || (is_linux && !is_chromeos)) { jumbo_static_library("pixel_diff_test_support") { testonly = true sources = [ + "test/skia_gold_matching_algorithm.cc", + "test/skia_gold_matching_algorithm.h", "test/skia_gold_pixel_diff.cc", "test/skia_gold_pixel_diff.h", ] @@ -969,6 +916,7 @@ test("ui_base_unittests") { "//ui/base:ui_data_pack", "//ui/base/clipboard:clipboard_test", "//ui/base/clipboard:clipboard_types", + "//ui/base/cursor:unittests", "//ui/display", "//ui/events:events_base", "//ui/events:test_support", @@ -999,18 +947,13 @@ test("ui_base_unittests") { "accelerators/accelerator_unittest.cc", "accelerators/menu_label_accelerator_util_unittest.cc", "accelerators/system_media_controls_media_keys_listener_unittest.cc", - "cursor/cursor_unittest.cc", - "cursor/cursor_util_unittest.cc", "models/list_model_unittest.cc", "models/list_selection_model_unittest.cc", "models/tree_node_model_unittest.cc", "text/bytes_formatting_unittest.cc", "webui/web_ui_util_unittest.cc", ] - deps += [ - "//components/system_media_controls:test_support", - "//ui/base/cursor/mojom:cursor_type", - ] + deps += [ "//components/system_media_controls:test_support" ] if (is_linux) { sources += @@ -1033,8 +976,12 @@ test("ui_base_unittests") { } } + # TODO(crbug.com/1091985): Support CrOS. if (is_win || is_mac || (is_linux && !is_chromeos)) { - sources += [ "test/skia_gold_pixel_diff_unittest.cc" ] + sources += [ + "test/skia_gold_matching_algorithm_unittest.cc", + "test/skia_gold_pixel_diff_unittest.cc", + ] deps += [ ":pixel_diff_test_support" ] } @@ -1114,23 +1061,9 @@ test("ui_base_unittests") { if (is_win) { sources += [ "dragdrop/os_exchange_data_win_unittest.cc", + "view_prop_unittest.cc", "win/hwnd_subclass_unittest.cc", ] - - ldflags = [ - "/DELAYLOAD:d2d1.dll", - "/DELAYLOAD:d3d10_1.dll", - ] - libs = [ - "d2d1.lib", - "d3d10_1.lib", - "imm32.lib", - "oleacc.lib", - ] - } - - if (is_win) { - sources += [ "view_prop_unittest.cc" ] } if (is_android) { @@ -1146,6 +1079,7 @@ test("ui_base_unittests") { if (use_x11) { deps += [ + "//ui/base/x:unittests", "//ui/events/platform/x11", "//ui/gfx/x", ] @@ -1173,6 +1107,7 @@ test("ui_base_unittests") { "dragdrop/os_exchange_data_provider_x11_unittest.cc", "x/selection_requestor_unittest.cc", ] + deps += [ "//ui/gfx/x:unit_test" ] } if (is_chromeos) { diff --git a/chromium/ui/base/DEPS b/chromium/ui/base/DEPS index 9179ffdd1b2..10a3245a323 100644 --- a/chromium/ui/base/DEPS +++ b/chromium/ui/base/DEPS @@ -15,4 +15,5 @@ include_rules = [ "+ui/resources/grit/webui_resources.h", "+ui/strings/grit/app_locale_settings.h", "+ui/strings/grit/ui_strings.h", + "+url" ] diff --git a/chromium/ui/base/accelerators/accelerator.cc b/chromium/ui/base/accelerators/accelerator.cc index 2ab364badbe..7f26ef86fe9 100644 --- a/chromium/ui/base/accelerators/accelerator.cc +++ b/chromium/ui/base/accelerators/accelerator.cc @@ -135,17 +135,11 @@ Accelerator::Accelerator(const KeyEvent& key_event) #endif } -Accelerator::Accelerator(const Accelerator& accelerator) { - key_code_ = accelerator.key_code_; - key_state_ = accelerator.key_state_; - modifiers_ = accelerator.modifiers_; - time_stamp_ = accelerator.time_stamp_; - interrupted_by_mouse_event_ = accelerator.interrupted_by_mouse_event_; - source_device_id_ = accelerator.source_device_id_; -} +Accelerator::Accelerator(const Accelerator& accelerator) = default; -Accelerator::~Accelerator() { -} +Accelerator& Accelerator::operator=(const Accelerator& accelerator) = default; + +Accelerator::~Accelerator() = default; // static int Accelerator::MaskOutKeyEventFlags(int flags) { @@ -159,17 +153,6 @@ KeyEvent Accelerator::ToKeyEvent() const { key_code(), modifiers(), time_stamp()); } -Accelerator& Accelerator::operator=(const Accelerator& accelerator) { - if (this != &accelerator) { - key_code_ = accelerator.key_code_; - key_state_ = accelerator.key_state_; - modifiers_ = accelerator.modifiers_; - time_stamp_ = accelerator.time_stamp_; - interrupted_by_mouse_event_ = accelerator.interrupted_by_mouse_event_; - } - return *this; -} - bool Accelerator::operator <(const Accelerator& rhs) const { const int modifiers_with_mask = MaskOutKeyEventFlags(modifiers_); const int rhs_modifiers_with_mask = MaskOutKeyEventFlags(rhs.modifiers_); diff --git a/chromium/ui/base/accelerators/accelerator.h b/chromium/ui/base/accelerators/accelerator.h index d4b97e5b6ee..6111a3bf550 100644 --- a/chromium/ui/base/accelerators/accelerator.h +++ b/chromium/ui/base/accelerators/accelerator.h @@ -14,10 +14,10 @@ #include #include +#include "base/component_export.h" #include "base/strings/string16.h" #include "base/time/time.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" #include "ui/events/event_constants.h" #include "ui/events/keycodes/keyboard_codes.h" @@ -30,7 +30,7 @@ class KeyEvent; // for a particular KeyEvent matches an accelerator with or without the repeat // flag. A side effect of this is that == (and <) does not consider the // repeat flag in its comparison. -class UI_BASE_EXPORT Accelerator { +class COMPONENT_EXPORT(UI_BASE) Accelerator { public: enum class KeyState { PRESSED, @@ -48,6 +48,7 @@ class UI_BASE_EXPORT Accelerator { base::TimeTicks time_stamp = base::TimeTicks()); explicit Accelerator(const KeyEvent& key_event); Accelerator(const Accelerator& accelerator); + Accelerator& operator=(const Accelerator& accelerator); ~Accelerator(); // Masks out all the non-modifiers KeyEvent |flags| and returns only the @@ -56,8 +57,6 @@ class UI_BASE_EXPORT Accelerator { KeyEvent ToKeyEvent() const; - Accelerator& operator=(const Accelerator& accelerator); - // Define the < operator so that the KeyboardShortcut can be used as a key in // a std::map. bool operator <(const Accelerator& rhs) const; @@ -129,7 +128,7 @@ class UI_BASE_EXPORT Accelerator { // An interface that classes that want to register for keyboard accelerators // should implement. -class UI_BASE_EXPORT AcceleratorTarget { +class COMPONENT_EXPORT(UI_BASE) AcceleratorTarget { public: // Should return true if the accelerator was processed. virtual bool AcceleratorPressed(const Accelerator& accelerator) = 0; diff --git a/chromium/ui/base/accelerators/accelerator_history.h b/chromium/ui/base/accelerators/accelerator_history.h index e9413773dbb..5d5ece78516 100644 --- a/chromium/ui/base/accelerators/accelerator_history.h +++ b/chromium/ui/base/accelerators/accelerator_history.h @@ -7,15 +7,15 @@ #include +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/accelerators/accelerator.h" -#include "ui/base/ui_base_export.h" namespace ui { // Keeps track of the system-wide current and the most recent previous // key accelerators. -class UI_BASE_EXPORT AcceleratorHistory { +class COMPONENT_EXPORT(UI_BASE) AcceleratorHistory { public: AcceleratorHistory(); ~AcceleratorHistory(); diff --git a/chromium/ui/base/accelerators/accelerator_manager.h b/chromium/ui/base/accelerators/accelerator_manager.h index 9eeec5ce99e..6d7c88604a0 100644 --- a/chromium/ui/base/accelerators/accelerator_manager.h +++ b/chromium/ui/base/accelerators/accelerator_manager.h @@ -10,16 +10,16 @@ #include #include +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/accelerators/accelerator.h" -#include "ui/base/ui_base_export.h" #include "ui/events/event_constants.h" namespace ui { // AcceleratorManger handles processing of accelerators. A delegate may be // supplied which is notified as unique accelerators are added and removed. -class UI_BASE_EXPORT AcceleratorManager { +class COMPONENT_EXPORT(UI_BASE) AcceleratorManager { public: enum HandlerPriority { kNormalPriority, diff --git a/chromium/ui/base/accelerators/global_media_keys_listener_win.h b/chromium/ui/base/accelerators/global_media_keys_listener_win.h index 8de4946c61c..2f20ba52397 100644 --- a/chromium/ui/base/accelerators/global_media_keys_listener_win.h +++ b/chromium/ui/base/accelerators/global_media_keys_listener_win.h @@ -5,10 +5,10 @@ #ifndef UI_BASE_ACCELERATORS_GLOBAL_MEDIA_KEYS_LISTENER_WIN_H_ #define UI_BASE_ACCELERATORS_GLOBAL_MEDIA_KEYS_LISTENER_WIN_H_ +#include "base/component_export.h" #include "base/containers/flat_map.h" #include "base/win/windows_types.h" #include "ui/base/accelerators/media_keys_listener.h" -#include "ui/base/ui_base_export.h" #include "ui/events/keycodes/keyboard_codes.h" namespace gfx { @@ -22,7 +22,8 @@ namespace ui { // Implementation of MediaKeysListener that uses RegisterHotKey to globally // listen for media key presses. It only allows for a single instance to be // created in order to prevent conflicts form multiple listeners. -class UI_BASE_EXPORT GlobalMediaKeysListenerWin : public MediaKeysListener { +class COMPONENT_EXPORT(UI_BASE) GlobalMediaKeysListenerWin + : public MediaKeysListener { public: explicit GlobalMediaKeysListenerWin(MediaKeysListener::Delegate* delegate); ~GlobalMediaKeysListenerWin() override; diff --git a/chromium/ui/base/accelerators/media_keys_listener.h b/chromium/ui/base/accelerators/media_keys_listener.h index 997718d8aff..6787fa39da1 100644 --- a/chromium/ui/base/accelerators/media_keys_listener.h +++ b/chromium/ui/base/accelerators/media_keys_listener.h @@ -8,8 +8,8 @@ #include #include "base/callback.h" +#include "base/component_export.h" #include "base/observer_list_types.h" -#include "ui/base/ui_base_export.h" #include "ui/events/keycodes/keyboard_codes.h" namespace ui { @@ -17,7 +17,7 @@ namespace ui { class Accelerator; // Create MediaKeyListener to receive accelerators on media keys. -class UI_BASE_EXPORT MediaKeysListener { +class COMPONENT_EXPORT(UI_BASE) MediaKeysListener { public: enum class Scope { kGlobal, // Listener works whenever application in focus or not. @@ -25,7 +25,7 @@ class UI_BASE_EXPORT MediaKeysListener { }; // Media keys accelerators receiver. - class UI_BASE_EXPORT Delegate : public base::CheckedObserver { + class COMPONENT_EXPORT(UI_BASE) Delegate : public base::CheckedObserver { public: ~Delegate() override; diff --git a/chromium/ui/base/accelerators/media_keys_listener_mac.mm b/chromium/ui/base/accelerators/media_keys_listener_mac.mm index 85378bb565d..6052fd13ff3 100644 --- a/chromium/ui/base/accelerators/media_keys_listener_mac.mm +++ b/chromium/ui/base/accelerators/media_keys_listener_mac.mm @@ -11,6 +11,7 @@ #include #include "base/containers/flat_set.h" +#include "base/logging.h" #include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/system_media_controls_media_keys_listener.h" diff --git a/chromium/ui/base/accelerators/media_keys_util.h b/chromium/ui/base/accelerators/media_keys_util.h index 95a98d58598..029a9572f7f 100644 --- a/chromium/ui/base/accelerators/media_keys_util.h +++ b/chromium/ui/base/accelerators/media_keys_util.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_ACCELERATORS_MEDIA_KEYS_UTIL_H_ #define UI_BASE_ACCELERATORS_MEDIA_KEYS_UTIL_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -24,12 +24,13 @@ enum class MediaHardwareKeyAction { }; // The name of the histogram that records |MediaHardwareKeyAction|. -UI_BASE_EXPORT extern const char kMediaHardwareKeyActionHistogramName[]; +COMPONENT_EXPORT(UI_BASE) +extern const char kMediaHardwareKeyActionHistogramName[]; // Records a media hardware key action to the // |kMediaHardwareKeyActionHistogramName| histogram. -UI_BASE_EXPORT void RecordMediaHardwareKeyAction( - ui::MediaHardwareKeyAction action); +COMPONENT_EXPORT(UI_BASE) +void RecordMediaHardwareKeyAction(ui::MediaHardwareKeyAction action); } // namespace ui diff --git a/chromium/ui/base/accelerators/menu_label_accelerator_util.h b/chromium/ui/base/accelerators/menu_label_accelerator_util.h index d70b21b6a34..fcdcd206a09 100644 --- a/chromium/ui/base/accelerators/menu_label_accelerator_util.h +++ b/chromium/ui/base/accelerators/menu_label_accelerator_util.h @@ -7,17 +7,17 @@ #include +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace ui { -UI_BASE_EXPORT base::char16 GetMnemonic(const base::string16& label); +COMPONENT_EXPORT(UI_BASE) base::char16 GetMnemonic(const base::string16& label); // This function escapes every '&' in label by replacing it with '&&', to avoid // having single ampersands in user-provided strings treated as accelerators. -UI_BASE_EXPORT base::string16 EscapeMenuLabelAmpersands( - const base::string16& label); +COMPONENT_EXPORT(UI_BASE) +base::string16 EscapeMenuLabelAmpersands(const base::string16& label); } // namespace ui diff --git a/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.h b/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.h index 3d1c5d073f5..d799fb5ec28 100644 --- a/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.h +++ b/chromium/ui/base/accelerators/menu_label_accelerator_util_linux.h @@ -7,18 +7,18 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { // Change windows accelerator style to GTK style. (GTK uses _ for // accelerators. Windows uses & with && as an escape for &.) -UI_BASE_EXPORT std::string ConvertAcceleratorsFromWindowsStyle( - const std::string& label); +COMPONENT_EXPORT(UI_BASE) +std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label); // Removes the "&" accelerators from a Windows label. -UI_BASE_EXPORT std::string RemoveWindowsStyleAccelerators( - const std::string& label); +COMPONENT_EXPORT(UI_BASE) +std::string RemoveWindowsStyleAccelerators(const std::string& label); } // namespace ui diff --git a/chromium/ui/base/accelerators/platform_accelerator_cocoa.h b/chromium/ui/base/accelerators/platform_accelerator_cocoa.h index 9feb15fab9a..26e93bd6f08 100644 --- a/chromium/ui/base/accelerators/platform_accelerator_cocoa.h +++ b/chromium/ui/base/accelerators/platform_accelerator_cocoa.h @@ -7,8 +7,8 @@ #import +#include "base/component_export.h" #include "ui/base/accelerators/accelerator.h" -#include "ui/base/ui_base_export.h" namespace ui { @@ -19,7 +19,8 @@ namespace ui { // accelerators have an associated NSMenuItem. Each NSMenuItem is specified with // a |key_equivalent| and |modifier_mask|. This function takes a ui::Accelerator // and returns the associated |key_equivalent| and |modifier_mask|. -UI_BASE_EXPORT void GetKeyEquivalentAndModifierMaskFromAccelerator( +COMPONENT_EXPORT(UI_BASE) +void GetKeyEquivalentAndModifierMaskFromAccelerator( const ui::Accelerator& accelerator, NSString** key_equivalent, NSUInteger* modifier_mask); diff --git a/chromium/ui/base/accelerators/system_media_controls_media_keys_listener.h b/chromium/ui/base/accelerators/system_media_controls_media_keys_listener.h index 2159509caa6..847669a515e 100644 --- a/chromium/ui/base/accelerators/system_media_controls_media_keys_listener.h +++ b/chromium/ui/base/accelerators/system_media_controls_media_keys_listener.h @@ -5,10 +5,10 @@ #ifndef UI_BASE_ACCELERATORS_SYSTEM_MEDIA_CONTROLS_MEDIA_KEYS_LISTENER_H_ #define UI_BASE_ACCELERATORS_SYSTEM_MEDIA_CONTROLS_MEDIA_KEYS_LISTENER_H_ +#include "base/component_export.h" #include "base/containers/flat_set.h" #include "components/system_media_controls/system_media_controls_observer.h" #include "ui/base/accelerators/media_keys_listener.h" -#include "ui/base/ui_base_export.h" #include "ui/events/keycodes/keyboard_codes.h" namespace system_media_controls { @@ -20,7 +20,7 @@ namespace ui { // Implementation of MediaKeysListener that uses the SystemMediaControls API to // listen for media key presses. It only allows for a single instance to be // created in order to prevent conflicts from multiple listeners. -class UI_BASE_EXPORT SystemMediaControlsMediaKeysListener +class COMPONENT_EXPORT(UI_BASE) SystemMediaControlsMediaKeysListener : public MediaKeysListener, public system_media_controls::SystemMediaControlsObserver { public: diff --git a/chromium/ui/base/base_window.h b/chromium/ui/base/base_window.h index 1719233015b..c4695328177 100644 --- a/chromium/ui/base/base_window.h +++ b/chromium/ui/base/base_window.h @@ -6,6 +6,7 @@ #define UI_BASE_BASE_WINDOW_H_ #include "base/compiler_specific.h" +#include "base/component_export.h" #include "build/build_config.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/native_widget_types.h" @@ -18,7 +19,7 @@ namespace ui { // Provides an interface to perform actions on windows, and query window // state. -class UI_BASE_EXPORT BaseWindow { +class COMPONENT_EXPORT(UI_BASE) BaseWindow { public: // Returns true if the window is currently the active/focused window. virtual bool IsActive() const = 0; diff --git a/chromium/ui/base/class_property.h b/chromium/ui/base/class_property.h index d7fcf47d318..4af52aef43d 100644 --- a/chromium/ui/base/class_property.h +++ b/chromium/ui/base/class_property.h @@ -10,8 +10,8 @@ #include #include +#include "base/component_export.h" #include "base/time/time.h" -#include "ui/base/ui_base_export.h" #include "ui/base/ui_base_types.h" // This header should be included by code that defines ClassProperties. @@ -64,7 +64,7 @@ class PropertyHelper; } -class UI_BASE_EXPORT PropertyHandler { +class COMPONENT_EXPORT(UI_BASE) PropertyHandler { public: PropertyHandler(); PropertyHandler(PropertyHandler&& other); @@ -166,7 +166,7 @@ class ClassPropertyCaster { namespace subtle { -class UI_BASE_EXPORT PropertyHelper { +class COMPONENT_EXPORT(UI_BASE) PropertyHelper { public: template static void Set(::ui::PropertyHandler* handler, diff --git a/chromium/ui/base/clipboard/BUILD.gn b/chromium/ui/base/clipboard/BUILD.gn index 61570cc1f2e..b36512c4c36 100644 --- a/chromium/ui/base/clipboard/BUILD.gn +++ b/chromium/ui/base/clipboard/BUILD.gn @@ -20,29 +20,30 @@ jumbo_component("clipboard_types") { "clipboard_constants.h", ] + if (!is_ios) { + sources += [ "clipboard_format_type.h" ] + } + if (is_android) { sources += [ "clipboard_format_type_android.cc" ] } if (is_mac) { - sources += [ - "clipboard_constants_mac.mm", - "clipboard_format_type_mac.mm", - ] + sources += [ "clipboard_format_type_mac.mm" ] + } + + if (is_mac || is_ios) { + sources += [ "clipboard_constants_mac.mm" ] } if (is_win) { sources += [ "clipboard_format_type_win.cc" ] } - if (!is_ios) { - if (use_aura) { - if ((use_x11 && is_desktop_linux) || !is_win) { - sources += [ "clipboard_format_type_aura.cc" ] - } + if (use_aura) { + if ((use_x11 && is_desktop_linux) || !is_win) { + sources += [ "clipboard_format_type_aura.cc" ] } - - sources += [ "clipboard_format_type.h" ] } defines = [ "IS_UI_BASE_CLIPBOARD_TYPES_IMPL" ] @@ -50,11 +51,11 @@ jumbo_component("clipboard_types") { deps = [ "//base" ] libs = [] + if (is_mac || is_ios) { + libs += [ "Foundation.framework" ] + } if (is_mac) { - libs += [ - "AppKit.framework", - "CoreFoundation.framework", - ] + libs += [ "AppKit.framework" ] } } @@ -64,6 +65,8 @@ jumbo_component("clipboard") { sources = [ "clipboard.cc", "clipboard.h", + "clipboard_metrics.cc", + "clipboard_metrics.h", "clipboard_monitor.cc", "clipboard_monitor.h", "clipboard_observer.h", @@ -112,16 +115,17 @@ jumbo_component("clipboard") { public_deps = [ ":clipboard_types" ] if (use_aura) { - # Aura clipboard. - # Chromecast uses clipboard_aura now. + # Linux clipboard implementations. if (is_desktop_linux && !is_chromecast) { + sources += [ "clipboard_linux.cc" ] if (use_ozone) { sources += [ "clipboard_ozone.cc", "clipboard_ozone.h", ] deps += [ "//ui/base" ] - } else if (use_x11) { + } + if (use_x11) { sources += [ "clipboard_x11.cc", "clipboard_x11.h", @@ -136,20 +140,20 @@ jumbo_component("clipboard") { ] } } else if (is_chromeos && ozone_platform_x11) { - # linux-chromeos uses aura clipboard by default, but supports ozone x11 - # with flag --use-system-clipbboard. + # linux-chromeos uses non-backed clipboard by default, but supports ozone + # x11 with flag --use-system-clipbboard. sources += [ - "clipboard_aura.cc", - "clipboard_aura.h", + "clipboard_non_backed.cc", + "clipboard_non_backed.h", "clipboard_ozone.cc", "clipboard_ozone.h", ] deps += [ "//ui/base" ] } else if (!is_win) { - # This file is used for all non-X11, non-Windows aura Builds. + # This file is used for all builds not backed by an underlying platform. sources += [ - "clipboard_aura.cc", - "clipboard_aura.h", + "clipboard_non_backed.cc", + "clipboard_non_backed.h", ] } } @@ -181,10 +185,10 @@ jumbo_source_set("clipboard_test_support") { "test/test_clipboard.cc", "test/test_clipboard.h", ] + } - if (is_android) { - sources += [ "clipboard_android_test_support.cc" ] - } + if (is_android) { + sources += [ "clipboard_android_test_support.cc" ] } public_deps = [ @@ -206,17 +210,17 @@ source_set("clipboard_test") { sources = [] output_name = "ui_base_clipboard_test" - if (is_mac) { + if (!is_ios) { sources += [ - "clipboard_mac_unittest.mm", - "clipboard_util_mac_unittest.mm", + "custom_data_helper_unittest.cc", + "test/test_clipboard_unittest.cc", ] } - if (!is_ios) { + if (is_mac) { sources += [ - "custom_data_helper_unittest.cc", - "test/test_clipboard_unittest.cc", + "clipboard_mac_unittest.mm", + "clipboard_util_mac_unittest.mm", ] } diff --git a/chromium/ui/base/clipboard/clipboard.cc b/chromium/ui/base/clipboard/clipboard.cc index a91de7c9517..a7722e261c1 100644 --- a/chromium/ui/base/clipboard/clipboard.cc +++ b/chromium/ui/base/clipboard/clipboard.cc @@ -203,4 +203,10 @@ base::Lock& Clipboard::ClipboardMapLock() { return *clipboard_map_lock; } +bool Clipboard::IsMarkedByOriginatorAsConfidential() const { + return false; +} + +void Clipboard::MarkAsConfidential() {} + } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard.h b/chromium/ui/base/clipboard/clipboard.h index 40f0e4d5e0d..1a69e8420d8 100644 --- a/chromium/ui/base/clipboard/clipboard.h +++ b/chromium/ui/base/clipboard/clipboard.h @@ -110,6 +110,17 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) Clipboard virtual bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer) const = 0; + // Returns whether the clipboard has data that is marked by its originator as + // confidential. This is available for opt-in checking by the user of this API + // as confidential information, like passwords, might legitimately need to be + // manipulated. + virtual bool IsMarkedByOriginatorAsConfidential() const; + + // Mark the data on the clipboard as being confidential. This isn't + // implemented for all platforms yet, but this call should be made on every + // platform so that when it is implemented on other platforms it is picked up. + virtual void MarkAsConfidential(); + // Clear the clipboard data. virtual void Clear(ClipboardBuffer buffer) = 0; diff --git a/chromium/ui/base/clipboard/clipboard_android.cc b/chromium/ui/base/clipboard/clipboard_android.cc index 501d191e961..917d0d9d135 100644 --- a/chromium/ui/base/clipboard/clipboard_android.cc +++ b/chromium/ui/base/clipboard/clipboard_android.cc @@ -21,10 +21,12 @@ #include "base/strings/utf_string_conversions.h" #include "base/synchronization/lock.h" #include "base/task/post_task.h" +#include "base/task/thread_pool.h" #include "base/thread_annotations.h" #include "base/time/time.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/ui_base_jni_headers/Clipboard_jni.h" #include "ui/gfx/android/java_bitmap.h" #include "ui/gfx/image/image.h" @@ -149,9 +151,8 @@ std::string ClipboardMap::Get(const std::string& format) { } void ClipboardMap::GetImage(ReadImageCallback callback) { - base::PostTaskAndReplyWithResult( - FROM_HERE, - {base::ThreadPool(), base::MayBlock(), base::TaskPriority::USER_BLOCKING}, + base::ThreadPool::PostTaskAndReplyWithResult( + FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING}, base::BindOnce(&GetImageData, clipboard_manager_), std::move(callback)); } @@ -432,6 +433,7 @@ void ClipboardAndroid::ReadAsciiText(ClipboardBuffer buffer, std::string* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kText); *result = g_map.Get().Get(ClipboardFormatType::GetPlainTextType().GetName()); } @@ -443,6 +445,7 @@ void ClipboardAndroid::ReadHTML(ClipboardBuffer buffer, uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kHtml); if (src_url) src_url->clear(); @@ -464,6 +467,7 @@ void ClipboardAndroid::ReadImage(ClipboardBuffer buffer, ReadImageCallback callback) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kImage); g_map.Get().GetImage(std::move(callback)); } @@ -483,6 +487,7 @@ void ClipboardAndroid::ReadBookmark(base::string16* title, void ClipboardAndroid::ReadData(const ClipboardFormatType& format, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kData); *result = g_map.Get().Get(format.GetName()); } diff --git a/chromium/ui/base/clipboard/clipboard_aura.cc b/chromium/ui/base/clipboard/clipboard_aura.cc deleted file mode 100644 index 9f4ae70a5ed..00000000000 --- a/chromium/ui/base/clipboard/clipboard_aura.cc +++ /dev/null @@ -1,626 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/base/clipboard/clipboard_aura.h" - -#include - -#include -#include -#include -#include - -#include "base/check_op.h" -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/memory/ptr_util.h" -#include "base/no_destructor.h" -#include "base/notreached.h" -#include "base/strings/utf_string_conversions.h" -#include "skia/ext/skia_utils_base.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/clipboard/clipboard_constants.h" -#include "ui/base/clipboard/clipboard_format_type.h" -#include "ui/base/clipboard/clipboard_monitor.h" -#include "ui/base/clipboard/custom_data_helper.h" -#include "ui/gfx/geometry/size.h" -#include "ui/ozone/buildflags.h" - -namespace ui { - -namespace { - -const size_t kMaxClipboardSize = 1; - -// Clipboard data format used by AuraClipboard. -enum class AuraClipboardFormat { - kText = 1 << 0, - kHtml = 1 << 1, - kRtf = 1 << 2, - kBookmark = 1 << 3, - kBitmap = 1 << 4, - kCustom = 1 << 5, - kWeb = 1 << 6, -}; - -// ClipboardData contains data copied to the Clipboard for a variety of formats. -// It mostly just provides APIs to cleanly access and manipulate this data. -class ClipboardData { - public: - ClipboardData() - : web_smart_paste_(false), - format_(0) {} - - virtual ~ClipboardData() = default; - - // Bitmask of AuraClipboardFormat types. - int format() const { return format_; } - - const std::string& text() const { return text_; } - void set_text(const std::string& text) { - text_ = text; - format_ |= static_cast(AuraClipboardFormat::kText); - } - - const std::string& markup_data() const { return markup_data_; } - void set_markup_data(const std::string& markup_data) { - markup_data_ = markup_data; - format_ |= static_cast(AuraClipboardFormat::kHtml); - } - - const std::string& rtf_data() const { return rtf_data_; } - void SetRTFData(const std::string& rtf_data) { - rtf_data_ = rtf_data; - format_ |= static_cast(AuraClipboardFormat::kRtf); - } - - const std::string& url() const { return url_; } - void set_url(const std::string& url) { - url_ = url; - format_ |= static_cast(AuraClipboardFormat::kHtml); - } - - const std::string& bookmark_title() const { return bookmark_title_; } - void set_bookmark_title(const std::string& bookmark_title) { - bookmark_title_ = bookmark_title; - format_ |= static_cast(AuraClipboardFormat::kBookmark); - } - - const std::string& bookmark_url() const { return bookmark_url_; } - void set_bookmark_url(const std::string& bookmark_url) { - bookmark_url_ = bookmark_url; - format_ |= static_cast(AuraClipboardFormat::kBookmark); - } - - const SkBitmap& bitmap() const { return bitmap_; } - void SetBitmapData(const SkBitmap& bitmap) { - if (!skia::SkBitmapToN32OpaqueOrPremul(bitmap, &bitmap_)) { - NOTREACHED() << "Unable to convert bitmap for clipboard"; - return; - } - format_ |= static_cast(AuraClipboardFormat::kBitmap); - } - - const std::string& custom_data_format() const { return custom_data_format_; } - const std::string& custom_data_data() const { return custom_data_data_; } - void SetCustomData(const std::string& data_format, - const std::string& data_data) { - if (data_data.size() == 0) { - custom_data_data_.clear(); - custom_data_format_.clear(); - return; - } - custom_data_data_ = data_data; - custom_data_format_ = data_format; - format_ |= static_cast(AuraClipboardFormat::kCustom); - } - - bool web_smart_paste() const { return web_smart_paste_; } - void set_web_smart_paste(bool web_smart_paste) { - web_smart_paste_ = web_smart_paste; - format_ |= static_cast(AuraClipboardFormat::kWeb); - } - - private: - // Plain text in UTF8 format. - std::string text_; - - // HTML markup data in UTF8 format. - std::string markup_data_; - std::string url_; - - // RTF data. - std::string rtf_data_; - - // Bookmark title in UTF8 format. - std::string bookmark_title_; - std::string bookmark_url_; - - // Filenames. - std::vector files_; - - // Bitmap images. - SkBitmap bitmap_; - - // Data with custom format. - std::string custom_data_format_; - std::string custom_data_data_; - - // WebKit smart paste data. - bool web_smart_paste_; - - int format_; - - DISALLOW_COPY_AND_ASSIGN(ClipboardData); -}; - -} // namespace - -// Platform clipboard implementation for Aura. This handles things like format -// conversion, versioning of clipboard items etc. The goal is to roughly provide -// a substitute to platform clipboards on other platforms such as GtkClipboard -// on gtk or winapi clipboard on win. -class AuraClipboard { - public: - AuraClipboard() : sequence_number_(0) { - } - - ~AuraClipboard() = default; - - void Clear() { - sequence_number_++; - data_list_.clear(); - ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); - } - - uint64_t sequence_number() const { - return sequence_number_; - } - - // Returns the data currently on the top of the clipboard stack, nullptr if - // the clipboard stack is empty. - const ClipboardData* GetData() const { - if (data_list_.empty()) - return nullptr; - return data_list_.front().get(); - } - - // Returns true if the data on top of the clipboard stack has format |format| - // or another format that can be converted to |format|. - bool IsFormatAvailable(AuraClipboardFormat format) const { - switch (format) { - case AuraClipboardFormat::kText: - return HasFormat(AuraClipboardFormat::kText) || - HasFormat(AuraClipboardFormat::kBookmark); - default: - return HasFormat(format); - } - } - - // Reads text from the data at the top of clipboard stack. - void ReadText(base::string16* result) const { - std::string utf8_result; - ReadAsciiText(&utf8_result); - *result = base::UTF8ToUTF16(utf8_result); - } - - // Reads ASCII text from the data at the top of clipboard stack. - void ReadAsciiText(std::string* result) const { - result->clear(); - const ClipboardData* data = GetData(); - if (!data) - return; - if (HasFormat(AuraClipboardFormat::kText)) - *result = data->text(); - else if (HasFormat(AuraClipboardFormat::kHtml)) - *result = data->markup_data(); - else if (HasFormat(AuraClipboardFormat::kBookmark)) - *result = data->bookmark_url(); - } - - // Reads HTML from the data at the top of clipboard stack. - void ReadHTML(base::string16* markup, - std::string* src_url, - uint32_t* fragment_start, - uint32_t* fragment_end) const { - markup->clear(); - if (src_url) - src_url->clear(); - *fragment_start = 0; - *fragment_end = 0; - - if (!HasFormat(AuraClipboardFormat::kHtml)) - return; - - const ClipboardData* data = GetData(); - *markup = base::UTF8ToUTF16(data->markup_data()); - *src_url = data->url(); - - *fragment_start = 0; - DCHECK_LE(markup->length(), std::numeric_limits::max()); - *fragment_end = static_cast(markup->length()); - } - - // Reads RTF from the data at the top of clipboard stack. - void ReadRTF(std::string* result) const { - result->clear(); - const ClipboardData* data = GetData(); - if (!HasFormat(AuraClipboardFormat::kRtf)) - return; - - *result = data->rtf_data(); - } - - // Reads image from the data at the top of clipboard stack. - SkBitmap ReadImage() const { - SkBitmap img; - if (!HasFormat(AuraClipboardFormat::kBitmap)) - return img; - - // A shallow copy should be fine here, but just to be safe... - const SkBitmap& clipboard_bitmap = GetData()->bitmap(); - if (img.tryAllocPixels(clipboard_bitmap.info())) { - clipboard_bitmap.readPixels(img.info(), img.getPixels(), img.rowBytes(), - 0, 0); - } - return img; - } - - // Reads data of type |type| from the data at the top of clipboard stack. - void ReadCustomData(const base::string16& type, - base::string16* result) const { - result->clear(); - const ClipboardData* data = GetData(); - if (!HasFormat(AuraClipboardFormat::kCustom)) - return; - - ReadCustomDataForType(data->custom_data_data().c_str(), - data->custom_data_data().size(), type, result); - } - - // Reads bookmark from the data at the top of clipboard stack. - void ReadBookmark(base::string16* title, std::string* url) const { - if (title) - title->clear(); - if (url) - url->clear(); - if (!HasFormat(AuraClipboardFormat::kBookmark)) - return; - - const ClipboardData* data = GetData(); - if (title) - *title = base::UTF8ToUTF16(data->bookmark_title()); - if (url) - *url = data->bookmark_url(); - } - - void ReadData(const std::string& type, std::string* result) const { - result->clear(); - const ClipboardData* data = GetData(); - if (!HasFormat(AuraClipboardFormat::kCustom) || - type != data->custom_data_format()) - return; - - *result = data->custom_data_data(); - } - - // Writes |data| to the top of the clipboard stack. - void WriteData(std::unique_ptr data) { - DCHECK(data); - AddToListEnsuringSize(std::move(data)); - ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); - } - - private: - // True if the data on top of the clipboard stack has format |format|. - bool HasFormat(AuraClipboardFormat format) const { - const ClipboardData* data = GetData(); - return data ? data->format() & static_cast(format) : false; - } - - void AddToListEnsuringSize(std::unique_ptr data) { - DCHECK(data); - sequence_number_++; - data_list_.push_front(std::move(data)); - - // If the size of list becomes more than the maximum allowed, we delete the - // last element. - if (data_list_.size() > kMaxClipboardSize) { - data_list_.pop_back(); - } - } - - // Stack containing various versions of ClipboardData. - std::list> data_list_; - - // Sequence number uniquely identifying clipboard state. - uint64_t sequence_number_; - - DISALLOW_COPY_AND_ASSIGN(AuraClipboard); -}; - -// Helper class to build a ClipboardData object and write it to clipboard. -class ClipboardDataBuilder { - public: - static void CommitToClipboard(AuraClipboard* clipboard) { - clipboard->WriteData(TakeCurrentData()); - } - - static void WriteText(const char* text_data, size_t text_len) { - ClipboardData* data = GetCurrentData(); - data->set_text(std::string(text_data, text_len)); - } - - static void WriteHTML(const char* markup_data, - size_t markup_len, - const char* url_data, - size_t url_len) { - ClipboardData* data = GetCurrentData(); - data->set_markup_data(std::string(markup_data, markup_len)); - data->set_url(std::string(url_data, url_len)); - } - - static void WriteRTF(const char* rtf_data, size_t rtf_len) { - ClipboardData* data = GetCurrentData(); - data->SetRTFData(std::string(rtf_data, rtf_len)); - } - - static void WriteBookmark(const char* title_data, - size_t title_len, - const char* url_data, - size_t url_len) { - ClipboardData* data = GetCurrentData(); - data->set_bookmark_title(std::string(title_data, title_len)); - data->set_bookmark_url(std::string(url_data, url_len)); - } - - static void WriteWebSmartPaste() { - ClipboardData* data = GetCurrentData(); - data->set_web_smart_paste(true); - } - - static void WriteBitmap(const SkBitmap& bitmap) { - ClipboardData* data = GetCurrentData(); - data->SetBitmapData(bitmap); - } - - static void WriteData(const std::string& format, - const char* data_data, - size_t data_len) { - ClipboardData* data = GetCurrentData(); - data->SetCustomData(format, std::string(data_data, data_len)); - } - - private: - static ClipboardData* GetCurrentData() { - if (!current_data_) - current_data_ = new ClipboardData; - return current_data_; - } - - static std::unique_ptr TakeCurrentData() { - std::unique_ptr data = base::WrapUnique(GetCurrentData()); - current_data_ = nullptr; - return data; - } - // This is a raw pointer instead of a std::unique_ptr to avoid adding a - // static initializer. - static ClipboardData* current_data_; -}; - -ClipboardData* ClipboardDataBuilder::current_data_ = nullptr; - -// linux-chromeos uses aura clipboard by default, but supports ozone x11 -// with flag --use-system-clipbboard. -#if !defined(OS_CHROMEOS) || !BUILDFLAG(OZONE_PLATFORM_X11) -// Clipboard factory method. -Clipboard* Clipboard::Create() { - return new ClipboardAura; -} -#endif - -// ClipboardAura implementation. -ClipboardAura::ClipboardAura() - : clipboard_internal_(std::make_unique()) { - DCHECK(CalledOnValidThread()); -} - -ClipboardAura::~ClipboardAura() { - DCHECK(CalledOnValidThread()); -} - -void ClipboardAura::OnPreShutdown() {} - -uint64_t ClipboardAura::GetSequenceNumber(ClipboardBuffer buffer) const { - DCHECK(CalledOnValidThread()); - return clipboard_internal_->sequence_number(); -} - -bool ClipboardAura::IsFormatAvailable(const ClipboardFormatType& format, - ClipboardBuffer buffer) const { - DCHECK(CalledOnValidThread()); - DCHECK(IsSupportedClipboardBuffer(buffer)); - if (ClipboardFormatType::GetPlainTextType().Equals(format) || - ClipboardFormatType::GetUrlType().Equals(format)) - return clipboard_internal_->IsFormatAvailable(AuraClipboardFormat::kText); - if (ClipboardFormatType::GetHtmlType().Equals(format)) - return clipboard_internal_->IsFormatAvailable(AuraClipboardFormat::kHtml); - if (ClipboardFormatType::GetRtfType().Equals(format)) - return clipboard_internal_->IsFormatAvailable(AuraClipboardFormat::kRtf); - if (ClipboardFormatType::GetBitmapType().Equals(format)) - return clipboard_internal_->IsFormatAvailable(AuraClipboardFormat::kBitmap); - if (ClipboardFormatType::GetWebKitSmartPasteType().Equals(format)) - return clipboard_internal_->IsFormatAvailable(AuraClipboardFormat::kWeb); - const ClipboardData* data = clipboard_internal_->GetData(); - return data && data->custom_data_format() == format.GetName(); -} - -void ClipboardAura::Clear(ClipboardBuffer buffer) { - DCHECK(CalledOnValidThread()); - DCHECK(IsSupportedClipboardBuffer(buffer)); - clipboard_internal_->Clear(); -} - -void ClipboardAura::ReadAvailableTypes( - ClipboardBuffer buffer, - std::vector* types) const { - DCHECK(CalledOnValidThread()); - DCHECK(types); - - types->clear(); - if (IsFormatAvailable(ClipboardFormatType::GetPlainTextType(), buffer)) - types->push_back( - base::UTF8ToUTF16(ClipboardFormatType::GetPlainTextType().GetName())); - if (IsFormatAvailable(ClipboardFormatType::GetHtmlType(), buffer)) - types->push_back( - base::UTF8ToUTF16(ClipboardFormatType::GetHtmlType().GetName())); - if (IsFormatAvailable(ClipboardFormatType::GetRtfType(), buffer)) - types->push_back( - base::UTF8ToUTF16(ClipboardFormatType::GetRtfType().GetName())); - if (IsFormatAvailable(ClipboardFormatType::GetBitmapType(), buffer)) - types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); - - if (clipboard_internal_->IsFormatAvailable(AuraClipboardFormat::kCustom) && - clipboard_internal_->GetData()) { - ReadCustomDataTypes( - clipboard_internal_->GetData()->custom_data_data().c_str(), - clipboard_internal_->GetData()->custom_data_data().size(), types); - } -} - -std::vector -ClipboardAura::ReadAvailablePlatformSpecificFormatNames( - ClipboardBuffer buffer) const { - DCHECK(CalledOnValidThread()); - - std::vector types; - - // Includes all non-pickled AvailableTypes. - if (IsFormatAvailable(ClipboardFormatType::GetPlainTextType(), buffer)) { - types.push_back( - base::UTF8ToUTF16(ClipboardFormatType::GetPlainTextType().GetName())); - } - if (IsFormatAvailable(ClipboardFormatType::GetHtmlType(), buffer)) { - types.push_back( - base::UTF8ToUTF16(ClipboardFormatType::GetHtmlType().GetName())); - } - if (IsFormatAvailable(ClipboardFormatType::GetRtfType(), buffer)) { - types.push_back( - base::UTF8ToUTF16(ClipboardFormatType::GetRtfType().GetName())); - } - if (IsFormatAvailable(ClipboardFormatType::GetBitmapType(), buffer)) { - types.push_back(base::UTF8ToUTF16(kMimeTypePNG)); - } - - return types; -} - -void ClipboardAura::ReadText(ClipboardBuffer buffer, - base::string16* result) const { - DCHECK(CalledOnValidThread()); - clipboard_internal_->ReadText(result); -} - -void ClipboardAura::ReadAsciiText(ClipboardBuffer buffer, - std::string* result) const { - DCHECK(CalledOnValidThread()); - clipboard_internal_->ReadAsciiText(result); -} - -void ClipboardAura::ReadHTML(ClipboardBuffer buffer, - base::string16* markup, - std::string* src_url, - uint32_t* fragment_start, - uint32_t* fragment_end) const { - DCHECK(CalledOnValidThread()); - clipboard_internal_->ReadHTML(markup, src_url, fragment_start, fragment_end); -} - -void ClipboardAura::ReadRTF(ClipboardBuffer buffer, std::string* result) const { - DCHECK(CalledOnValidThread()); - clipboard_internal_->ReadRTF(result); -} - -void ClipboardAura::ReadImage(ClipboardBuffer buffer, - ReadImageCallback callback) const { - DCHECK(CalledOnValidThread()); - std::move(callback).Run(clipboard_internal_->ReadImage()); -} - -void ClipboardAura::ReadCustomData(ClipboardBuffer buffer, - const base::string16& type, - base::string16* result) const { - DCHECK(CalledOnValidThread()); - clipboard_internal_->ReadCustomData(type, result); -} - -void ClipboardAura::ReadBookmark(base::string16* title, - std::string* url) const { - DCHECK(CalledOnValidThread()); - clipboard_internal_->ReadBookmark(title, url); -} - -void ClipboardAura::ReadData(const ClipboardFormatType& format, - std::string* result) const { - DCHECK(CalledOnValidThread()); - clipboard_internal_->ReadData(format.GetName(), result); -} - -void ClipboardAura::WritePortableRepresentations(ClipboardBuffer buffer, - const ObjectMap& objects) { - DCHECK(CalledOnValidThread()); - DCHECK(IsSupportedClipboardBuffer(buffer)); - for (const auto& object : objects) - DispatchPortableRepresentation(object.first, object.second); - ClipboardDataBuilder::CommitToClipboard(clipboard_internal_.get()); -} - -void ClipboardAura::WritePlatformRepresentations( - ClipboardBuffer buffer, - std::vector platform_representations) { - DCHECK(CalledOnValidThread()); - DCHECK(IsSupportedClipboardBuffer(buffer)); - - DispatchPlatformRepresentations(std::move(platform_representations)); - - ClipboardDataBuilder::CommitToClipboard(clipboard_internal_.get()); -} - -void ClipboardAura::WriteText(const char* text_data, size_t text_len) { - ClipboardDataBuilder::WriteText(text_data, text_len); -} - -void ClipboardAura::WriteHTML(const char* markup_data, - size_t markup_len, - const char* url_data, - size_t url_len) { - ClipboardDataBuilder::WriteHTML(markup_data, markup_len, url_data, url_len); -} - -void ClipboardAura::WriteRTF(const char* rtf_data, size_t data_len) { - ClipboardDataBuilder::WriteRTF(rtf_data, data_len); -} - -void ClipboardAura::WriteBookmark(const char* title_data, - size_t title_len, - const char* url_data, - size_t url_len) { - ClipboardDataBuilder::WriteBookmark(title_data, title_len, url_data, url_len); -} - -void ClipboardAura::WriteWebSmartPaste() { - ClipboardDataBuilder::WriteWebSmartPaste(); -} - -void ClipboardAura::WriteBitmap(const SkBitmap& bitmap) { - ClipboardDataBuilder::WriteBitmap(bitmap); -} - -void ClipboardAura::WriteData(const ClipboardFormatType& format, - const char* data_data, - size_t data_len) { - ClipboardDataBuilder::WriteData(format.GetName(), data_data, data_len); -} - -} // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_aura.h b/chromium/ui/base/clipboard/clipboard_aura.h deleted file mode 100644 index 6a6862ba688..00000000000 --- a/chromium/ui/base/clipboard/clipboard_aura.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_CLIPBOARD_CLIPBOARD_AURA_H_ -#define UI_BASE_CLIPBOARD_CLIPBOARD_AURA_H_ - -#include -#include - -#include "base/macros.h" -#include "ui/base/clipboard/clipboard.h" - -namespace ui { - -class AuraClipboard; - -class ClipboardAura : public Clipboard { - private: - friend class Clipboard; - ClipboardAura(); - ~ClipboardAura() override; - - // Clipboard overrides: - void OnPreShutdown() override; - uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; - bool IsFormatAvailable(const ClipboardFormatType& format, - ClipboardBuffer buffer) const override; - void Clear(ClipboardBuffer buffer) override; - void ReadAvailableTypes(ClipboardBuffer buffer, - std::vector* types) const override; - std::vector ReadAvailablePlatformSpecificFormatNames( - ClipboardBuffer buffer) const override; - void ReadText(ClipboardBuffer buffer, base::string16* result) const override; - void ReadAsciiText(ClipboardBuffer buffer, - std::string* result) const override; - void ReadHTML(ClipboardBuffer buffer, - base::string16* markup, - std::string* src_url, - uint32_t* fragment_start, - uint32_t* fragment_end) const override; - void ReadRTF(ClipboardBuffer buffer, std::string* result) const override; - void ReadImage(ClipboardBuffer buffer, - ReadImageCallback callback) const override; - void ReadCustomData(ClipboardBuffer buffer, - const base::string16& type, - base::string16* result) const override; - void ReadBookmark(base::string16* title, std::string* url) const override; - void ReadData(const ClipboardFormatType& format, - std::string* result) const override; - void WritePortableRepresentations(ClipboardBuffer buffer, - const ObjectMap& objects) override; - void WritePlatformRepresentations( - ClipboardBuffer buffer, - std::vector platform_representations) - override; - void WriteText(const char* text_data, size_t text_len) override; - void WriteHTML(const char* markup_data, - size_t markup_len, - const char* url_data, - size_t url_len) override; - void WriteRTF(const char* rtf_data, size_t data_len) override; - void WriteBookmark(const char* title_data, - size_t title_len, - const char* url_data, - size_t url_len) override; - void WriteWebSmartPaste() override; - void WriteBitmap(const SkBitmap& bitmap) override; - void WriteData(const ClipboardFormatType& format, - const char* data_data, - size_t data_len) override; - - const std::unique_ptr clipboard_internal_; - - DISALLOW_COPY_AND_ASSIGN(ClipboardAura); -}; - -} // namespace ui - -#endif // UI_BASE_CLIPBOARD_CLIPBOARD_AURA_H_ diff --git a/chromium/ui/base/clipboard/clipboard_constants.h b/chromium/ui/base/clipboard/clipboard_constants.h index 52048077f19..f57524d56b6 100644 --- a/chromium/ui/base/clipboard/clipboard_constants.h +++ b/chromium/ui/base/clipboard/clipboard_constants.h @@ -44,13 +44,20 @@ extern const char kMimeTypePepperCustomData[]; // Pickled data. COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern NSString* const kWebCustomDataPboardType; + // Tells us if WebKit was the last to write to the pasteboard. There's no // actual data associated with this type. COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern NSString* const kWebSmartPastePboardType; + // Pepper custom data format type. COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) extern NSString* const kPepperCustomDataPboardType; + +// Data format used to tag the current data as confidential. +COMPONENT_EXPORT(UI_BASE_CLIPBOARD_TYPES) +extern NSString* const kUTTypeConfidentialData; + #endif // defined(OS_MACOSX) #if defined(OS_ANDROID) diff --git a/chromium/ui/base/clipboard/clipboard_constants_mac.mm b/chromium/ui/base/clipboard/clipboard_constants_mac.mm index 4f3029f6200..8633a201234 100644 --- a/chromium/ui/base/clipboard/clipboard_constants_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_constants_mac.mm @@ -14,4 +14,9 @@ NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; NSString* const kPepperCustomDataPboardType = @"org.chromium.pepper-custom-data"; +// It is the common convention on the Mac and on iOS that password managers tag +// confidential data with the flavor "org.nspasteboard.ConcealedType". Obey this +// convention. See http://nspasteboard.org/ for more info. +NSString* const kUTTypeConfidentialData = @"org.nspasteboard.ConcealedType"; + } // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_linux.cc b/chromium/ui/base/clipboard/clipboard_linux.cc new file mode 100644 index 00000000000..ef42052ed5d --- /dev/null +++ b/chromium/ui/base/clipboard/clipboard_linux.cc @@ -0,0 +1,33 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/clipboard/clipboard.h" + +#if defined(USE_OZONE) +#include "ui/base/clipboard/clipboard_ozone.h" +#include "ui/base/ui_base_features.h" +#endif + +#if defined(USE_X11) +#include "ui/base/clipboard/clipboard_x11.h" +#endif + +namespace ui { + +// Clipboard factory method. +Clipboard* Clipboard::Create() { +#if defined(USE_OZONE) + if (features::IsUsingOzonePlatform()) + return new ClipboardOzone(); +#endif + +#if defined(USE_X11) + return new ClipboardX11(); +#else + NOTREACHED(); + return nullptr; +#endif +} + +} // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_mac.h b/chromium/ui/base/clipboard/clipboard_mac.h index 9ebd21cd157..507a7f8c786 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.h +++ b/chromium/ui/base/clipboard/clipboard_mac.h @@ -33,6 +33,8 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ClipboardMac : public Clipboard { uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; bool IsFormatAvailable(const ClipboardFormatType& format, ClipboardBuffer buffer) const override; + bool IsMarkedByOriginatorAsConfidential() const override; + void MarkAsConfidential() override; void Clear(ClipboardBuffer buffer) override; void ReadAvailableTypes(ClipboardBuffer buffer, std::vector* types) const override; diff --git a/chromium/ui/base/clipboard/clipboard_mac.mm b/chromium/ui/base/clipboard/clipboard_mac.mm index 4c8e0e874b0..c396f9effea 100644 --- a/chromium/ui/base/clipboard/clipboard_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_mac.mm @@ -24,6 +24,7 @@ #import "third_party/mozilla/NSPasteboard+Utils.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_util_mac.h" #include "ui/base/clipboard/custom_data_helper.h" #include "ui/gfx/canvas.h" @@ -85,6 +86,27 @@ bool ClipboardMac::IsFormatAvailable(const ClipboardFormatType& format, return [types containsObject:format.ToNSString()]; } +bool ClipboardMac::IsMarkedByOriginatorAsConfidential() const { + DCHECK(CalledOnValidThread()); + + NSPasteboard* pb = GetPasteboard(); + NSPasteboardType type = + [pb availableTypeFromArray:@[ kUTTypeConfidentialData ]]; + + if (type) + return true; + + return false; +} + +void ClipboardMac::MarkAsConfidential() { + DCHECK(CalledOnValidThread()); + + NSPasteboard* pb = GetPasteboard(); + [pb addTypes:@[ kUTTypeConfidentialData ] owner:nil]; + [pb setData:nil forType:kUTTypeConfidentialData]; +} + void ClipboardMac::Clear(ClipboardBuffer buffer) { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); @@ -138,6 +160,7 @@ void ClipboardMac::ReadText(ClipboardBuffer buffer, base::string16* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kText); NSPasteboard* pb = GetPasteboard(); NSString* contents = [pb stringForType:NSPasteboardTypeString]; @@ -148,6 +171,7 @@ void ClipboardMac::ReadAsciiText(ClipboardBuffer buffer, std::string* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kText); NSPasteboard* pb = GetPasteboard(); NSString* contents = [pb stringForType:NSPasteboardTypeString]; @@ -164,6 +188,7 @@ void ClipboardMac::ReadHTML(ClipboardBuffer buffer, uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kHtml); // TODO(avi): src_url? markup->clear(); @@ -191,12 +216,14 @@ void ClipboardMac::ReadHTML(ClipboardBuffer buffer, void ClipboardMac::ReadRTF(ClipboardBuffer buffer, std::string* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kRtf); return ReadData(ClipboardFormatType::GetRtfType(), result); } void ClipboardMac::ReadImage(ClipboardBuffer buffer, ReadImageCallback callback) const { + RecordRead(ClipboardFormatMetric::kImage); std::move(callback).Run(ReadImageInternal(buffer, GetPasteboard())); } @@ -205,6 +232,7 @@ void ClipboardMac::ReadCustomData(ClipboardBuffer buffer, base::string16* result) const { DCHECK(CalledOnValidThread()); DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kCustomData); NSPasteboard* pb = GetPasteboard(); if ([[pb types] containsObject:kWebCustomDataPboardType]) { @@ -216,6 +244,7 @@ void ClipboardMac::ReadCustomData(ClipboardBuffer buffer, void ClipboardMac::ReadBookmark(base::string16* title, std::string* url) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kBookmark); NSPasteboard* pb = GetPasteboard(); if (title) { @@ -235,6 +264,7 @@ void ClipboardMac::ReadBookmark(base::string16* title, std::string* url) const { void ClipboardMac::ReadData(const ClipboardFormatType& format, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kData); NSPasteboard* pb = GetPasteboard(); NSData* data = [pb dataForType:format.ToNSString()]; if ([data length]) diff --git a/chromium/ui/base/clipboard/clipboard_metrics.cc b/chromium/ui/base/clipboard/clipboard_metrics.cc new file mode 100644 index 00000000000..dc52ad67926 --- /dev/null +++ b/chromium/ui/base/clipboard/clipboard_metrics.cc @@ -0,0 +1,20 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/clipboard/clipboard_metrics.h" + +#include "base/metrics/histogram_functions.h" +#include "base/metrics/histogram_macros.h" + +namespace ui { + +void RecordRead(ClipboardFormatMetric metric) { + base::UmaHistogramEnumeration("Clipboard.Read", metric); +} + +void RecordWrite(ClipboardFormatMetric metric) { + base::UmaHistogramEnumeration("Clipboard.Write", metric); +} + +} // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_metrics.h b/chromium/ui/base/clipboard/clipboard_metrics.h new file mode 100644 index 00000000000..5077043bafe --- /dev/null +++ b/chromium/ui/base/clipboard/clipboard_metrics.h @@ -0,0 +1,30 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_CLIPBOARD_CLIPBOARD_METRICS_H_ +#define UI_BASE_CLIPBOARD_CLIPBOARD_METRICS_H_ + +namespace ui { + +// Used to log formats read/written from/to the platform clipboard. +// +// This enum's values are persisted to logs. Do not reuse or renumber values. +enum class ClipboardFormatMetric { + kText = 0, // On applicable platforms, includes both UNICODE and ANSI text. + kHtml = 1, + kRtf = 2, + kImage = 3, + kBookmark = 4, + kData = 5, + kCustomData = 6, + kWebSmartPaste = 7, // Only used on write. + kMaxValue = kWebSmartPaste, +}; + +void RecordRead(ClipboardFormatMetric metric); +void RecordWrite(ClipboardFormatMetric metric); + +} // namespace ui + +#endif // UI_BASE_CLIPBOARD_CLIPBOARD_MONITOR_H_ diff --git a/chromium/ui/base/clipboard/clipboard_non_backed.cc b/chromium/ui/base/clipboard/clipboard_non_backed.cc new file mode 100644 index 00000000000..2b827891f6d --- /dev/null +++ b/chromium/ui/base/clipboard/clipboard_non_backed.cc @@ -0,0 +1,636 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/clipboard/clipboard_non_backed.h" + +#include + +#include +#include +#include +#include + +#include "base/check_op.h" +#include "base/files/file_path.h" +#include "base/macros.h" +#include "base/memory/ptr_util.h" +#include "base/no_destructor.h" +#include "base/notreached.h" +#include "base/strings/utf_string_conversions.h" +#include "skia/ext/skia_utils_base.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/clipboard/clipboard_format_type.h" +#include "ui/base/clipboard/clipboard_metrics.h" +#include "ui/base/clipboard/clipboard_monitor.h" +#include "ui/base/clipboard/custom_data_helper.h" +#include "ui/gfx/geometry/size.h" +#include "ui/ozone/buildflags.h" + +namespace ui { + +namespace { + +const size_t kMaxClipboardSize = 1; + +// Clipboard data format used by ClipboardInternal. +enum class ClipboardInternalFormat { + kText = 1 << 0, + kHtml = 1 << 1, + kRtf = 1 << 2, + kBookmark = 1 << 3, + kBitmap = 1 << 4, + kCustom = 1 << 5, + kWeb = 1 << 6, +}; + +// ClipboardData contains data copied to the Clipboard for a variety of formats. +// It mostly just provides APIs to cleanly access and manipulate this data. +class ClipboardData { + public: + ClipboardData() : web_smart_paste_(false), format_(0) {} + + virtual ~ClipboardData() = default; + + // Bitmask of ClipboardInternalFormat types. + int format() const { return format_; } + + const std::string& text() const { return text_; } + void set_text(const std::string& text) { + text_ = text; + format_ |= static_cast(ClipboardInternalFormat::kText); + } + + const std::string& markup_data() const { return markup_data_; } + void set_markup_data(const std::string& markup_data) { + markup_data_ = markup_data; + format_ |= static_cast(ClipboardInternalFormat::kHtml); + } + + const std::string& rtf_data() const { return rtf_data_; } + void SetRTFData(const std::string& rtf_data) { + rtf_data_ = rtf_data; + format_ |= static_cast(ClipboardInternalFormat::kRtf); + } + + const std::string& url() const { return url_; } + void set_url(const std::string& url) { + url_ = url; + format_ |= static_cast(ClipboardInternalFormat::kHtml); + } + + const std::string& bookmark_title() const { return bookmark_title_; } + void set_bookmark_title(const std::string& bookmark_title) { + bookmark_title_ = bookmark_title; + format_ |= static_cast(ClipboardInternalFormat::kBookmark); + } + + const std::string& bookmark_url() const { return bookmark_url_; } + void set_bookmark_url(const std::string& bookmark_url) { + bookmark_url_ = bookmark_url; + format_ |= static_cast(ClipboardInternalFormat::kBookmark); + } + + const SkBitmap& bitmap() const { return bitmap_; } + void SetBitmapData(const SkBitmap& bitmap) { + if (!skia::SkBitmapToN32OpaqueOrPremul(bitmap, &bitmap_)) { + NOTREACHED() << "Unable to convert bitmap for clipboard"; + return; + } + format_ |= static_cast(ClipboardInternalFormat::kBitmap); + } + + const std::string& custom_data_format() const { return custom_data_format_; } + const std::string& custom_data_data() const { return custom_data_data_; } + void SetCustomData(const std::string& data_format, + const std::string& data_data) { + if (data_data.size() == 0) { + custom_data_data_.clear(); + custom_data_format_.clear(); + return; + } + custom_data_data_ = data_data; + custom_data_format_ = data_format; + format_ |= static_cast(ClipboardInternalFormat::kCustom); + } + + bool web_smart_paste() const { return web_smart_paste_; } + void set_web_smart_paste(bool web_smart_paste) { + web_smart_paste_ = web_smart_paste; + format_ |= static_cast(ClipboardInternalFormat::kWeb); + } + + private: + // Plain text in UTF8 format. + std::string text_; + + // HTML markup data in UTF8 format. + std::string markup_data_; + std::string url_; + + // RTF data. + std::string rtf_data_; + + // Bookmark title in UTF8 format. + std::string bookmark_title_; + std::string bookmark_url_; + + // Filenames. + std::vector files_; + + // Bitmap images. + SkBitmap bitmap_; + + // Data with custom format. + std::string custom_data_format_; + std::string custom_data_data_; + + // WebKit smart paste data. + bool web_smart_paste_; + + int format_; + + DISALLOW_COPY_AND_ASSIGN(ClipboardData); +}; + +} // namespace + +// Simple, internal implementation of a clipboard, handling things like format +// conversion, versioning, etc. +class ClipboardInternal { + public: + ClipboardInternal() : sequence_number_(0) {} + + ~ClipboardInternal() = default; + + void Clear() { + sequence_number_++; + data_list_.clear(); + ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); + } + + uint64_t sequence_number() const { return sequence_number_; } + + // Returns the data currently on the top of the clipboard stack, nullptr if + // the clipboard stack is empty. + const ClipboardData* GetData() const { + if (data_list_.empty()) + return nullptr; + return data_list_.front().get(); + } + + // Returns true if the data on top of the clipboard stack has format |format| + // or another format that can be converted to |format|. + bool IsFormatAvailable(ClipboardInternalFormat format) const { + switch (format) { + case ClipboardInternalFormat::kText: + return HasFormat(ClipboardInternalFormat::kText) || + HasFormat(ClipboardInternalFormat::kBookmark); + default: + return HasFormat(format); + } + } + + // Reads text from the data at the top of clipboard stack. + void ReadText(base::string16* result) const { + std::string utf8_result; + ReadAsciiText(&utf8_result); + *result = base::UTF8ToUTF16(utf8_result); + } + + // Reads ASCII text from the data at the top of clipboard stack. + void ReadAsciiText(std::string* result) const { + result->clear(); + const ClipboardData* data = GetData(); + if (!data) + return; + if (HasFormat(ClipboardInternalFormat::kText)) + *result = data->text(); + else if (HasFormat(ClipboardInternalFormat::kHtml)) + *result = data->markup_data(); + else if (HasFormat(ClipboardInternalFormat::kBookmark)) + *result = data->bookmark_url(); + } + + // Reads HTML from the data at the top of clipboard stack. + void ReadHTML(base::string16* markup, + std::string* src_url, + uint32_t* fragment_start, + uint32_t* fragment_end) const { + markup->clear(); + if (src_url) + src_url->clear(); + *fragment_start = 0; + *fragment_end = 0; + + if (!HasFormat(ClipboardInternalFormat::kHtml)) + return; + + const ClipboardData* data = GetData(); + *markup = base::UTF8ToUTF16(data->markup_data()); + *src_url = data->url(); + + *fragment_start = 0; + DCHECK_LE(markup->length(), std::numeric_limits::max()); + *fragment_end = static_cast(markup->length()); + } + + // Reads RTF from the data at the top of clipboard stack. + void ReadRTF(std::string* result) const { + result->clear(); + const ClipboardData* data = GetData(); + if (!HasFormat(ClipboardInternalFormat::kRtf)) + return; + + *result = data->rtf_data(); + } + + // Reads image from the data at the top of clipboard stack. + SkBitmap ReadImage() const { + SkBitmap img; + if (!HasFormat(ClipboardInternalFormat::kBitmap)) + return img; + + // A shallow copy should be fine here, but just to be safe... + const SkBitmap& clipboard_bitmap = GetData()->bitmap(); + if (img.tryAllocPixels(clipboard_bitmap.info())) { + clipboard_bitmap.readPixels(img.info(), img.getPixels(), img.rowBytes(), + 0, 0); + } + return img; + } + + // Reads data of type |type| from the data at the top of clipboard stack. + void ReadCustomData(const base::string16& type, + base::string16* result) const { + result->clear(); + const ClipboardData* data = GetData(); + if (!HasFormat(ClipboardInternalFormat::kCustom)) + return; + + ReadCustomDataForType(data->custom_data_data().c_str(), + data->custom_data_data().size(), type, result); + } + + // Reads bookmark from the data at the top of clipboard stack. + void ReadBookmark(base::string16* title, std::string* url) const { + if (title) + title->clear(); + if (url) + url->clear(); + if (!HasFormat(ClipboardInternalFormat::kBookmark)) + return; + + const ClipboardData* data = GetData(); + if (title) + *title = base::UTF8ToUTF16(data->bookmark_title()); + if (url) + *url = data->bookmark_url(); + } + + void ReadData(const std::string& type, std::string* result) const { + result->clear(); + const ClipboardData* data = GetData(); + if (!HasFormat(ClipboardInternalFormat::kCustom) || + type != data->custom_data_format()) + return; + + *result = data->custom_data_data(); + } + + // Writes |data| to the top of the clipboard stack. + void WriteData(std::unique_ptr data) { + DCHECK(data); + AddToListEnsuringSize(std::move(data)); + ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); + } + + private: + // True if the data on top of the clipboard stack has format |format|. + bool HasFormat(ClipboardInternalFormat format) const { + const ClipboardData* data = GetData(); + return data ? data->format() & static_cast(format) : false; + } + + void AddToListEnsuringSize(std::unique_ptr data) { + DCHECK(data); + sequence_number_++; + data_list_.push_front(std::move(data)); + + // If the size of list becomes more than the maximum allowed, we delete the + // last element. + if (data_list_.size() > kMaxClipboardSize) { + data_list_.pop_back(); + } + } + + // Stack containing various versions of ClipboardData. + std::list> data_list_; + + // Sequence number uniquely identifying clipboard state. + uint64_t sequence_number_; + + DISALLOW_COPY_AND_ASSIGN(ClipboardInternal); +}; + +// Helper class to build a ClipboardData object and write it to clipboard. +class ClipboardDataBuilder { + public: + static void CommitToClipboard(ClipboardInternal* clipboard) { + clipboard->WriteData(TakeCurrentData()); + } + + static void WriteText(const char* text_data, size_t text_len) { + ClipboardData* data = GetCurrentData(); + data->set_text(std::string(text_data, text_len)); + } + + static void WriteHTML(const char* markup_data, + size_t markup_len, + const char* url_data, + size_t url_len) { + ClipboardData* data = GetCurrentData(); + data->set_markup_data(std::string(markup_data, markup_len)); + data->set_url(std::string(url_data, url_len)); + } + + static void WriteRTF(const char* rtf_data, size_t rtf_len) { + ClipboardData* data = GetCurrentData(); + data->SetRTFData(std::string(rtf_data, rtf_len)); + } + + static void WriteBookmark(const char* title_data, + size_t title_len, + const char* url_data, + size_t url_len) { + ClipboardData* data = GetCurrentData(); + data->set_bookmark_title(std::string(title_data, title_len)); + data->set_bookmark_url(std::string(url_data, url_len)); + } + + static void WriteWebSmartPaste() { + ClipboardData* data = GetCurrentData(); + data->set_web_smart_paste(true); + } + + static void WriteBitmap(const SkBitmap& bitmap) { + ClipboardData* data = GetCurrentData(); + data->SetBitmapData(bitmap); + } + + static void WriteData(const std::string& format, + const char* data_data, + size_t data_len) { + ClipboardData* data = GetCurrentData(); + data->SetCustomData(format, std::string(data_data, data_len)); + } + + private: + static ClipboardData* GetCurrentData() { + if (!current_data_) + current_data_ = new ClipboardData; + return current_data_; + } + + static std::unique_ptr TakeCurrentData() { + std::unique_ptr data = base::WrapUnique(GetCurrentData()); + current_data_ = nullptr; + return data; + } + // This is a raw pointer instead of a std::unique_ptr to avoid adding a + // static initializer. + static ClipboardData* current_data_; +}; + +ClipboardData* ClipboardDataBuilder::current_data_ = nullptr; + +// linux-chromeos uses non-backed clipboard by default, but supports ozone x11 +// with flag --use-system-clipbboard. +#if !defined(OS_CHROMEOS) || !BUILDFLAG(OZONE_PLATFORM_X11) +// Clipboard factory method. +Clipboard* Clipboard::Create() { + return new ClipboardNonBacked; +} +#endif + +// ClipboardNonBacked implementation. +ClipboardNonBacked::ClipboardNonBacked() + : clipboard_internal_(std::make_unique()) { + DCHECK(CalledOnValidThread()); +} + +ClipboardNonBacked::~ClipboardNonBacked() { + DCHECK(CalledOnValidThread()); +} + +void ClipboardNonBacked::OnPreShutdown() {} + +uint64_t ClipboardNonBacked::GetSequenceNumber(ClipboardBuffer buffer) const { + DCHECK(CalledOnValidThread()); + return clipboard_internal_->sequence_number(); +} + +bool ClipboardNonBacked::IsFormatAvailable(const ClipboardFormatType& format, + ClipboardBuffer buffer) const { + DCHECK(CalledOnValidThread()); + DCHECK(IsSupportedClipboardBuffer(buffer)); + if (ClipboardFormatType::GetPlainTextType().Equals(format) || + ClipboardFormatType::GetUrlType().Equals(format)) + return clipboard_internal_->IsFormatAvailable( + ClipboardInternalFormat::kText); + if (ClipboardFormatType::GetHtmlType().Equals(format)) + return clipboard_internal_->IsFormatAvailable( + ClipboardInternalFormat::kHtml); + if (ClipboardFormatType::GetRtfType().Equals(format)) + return clipboard_internal_->IsFormatAvailable( + ClipboardInternalFormat::kRtf); + if (ClipboardFormatType::GetBitmapType().Equals(format)) + return clipboard_internal_->IsFormatAvailable( + ClipboardInternalFormat::kBitmap); + if (ClipboardFormatType::GetWebKitSmartPasteType().Equals(format)) + return clipboard_internal_->IsFormatAvailable( + ClipboardInternalFormat::kWeb); + const ClipboardData* data = clipboard_internal_->GetData(); + return data && data->custom_data_format() == format.GetName(); +} + +void ClipboardNonBacked::Clear(ClipboardBuffer buffer) { + DCHECK(CalledOnValidThread()); + DCHECK(IsSupportedClipboardBuffer(buffer)); + clipboard_internal_->Clear(); +} + +void ClipboardNonBacked::ReadAvailableTypes( + ClipboardBuffer buffer, + std::vector* types) const { + DCHECK(CalledOnValidThread()); + DCHECK(types); + + types->clear(); + if (IsFormatAvailable(ClipboardFormatType::GetPlainTextType(), buffer)) + types->push_back( + base::UTF8ToUTF16(ClipboardFormatType::GetPlainTextType().GetName())); + if (IsFormatAvailable(ClipboardFormatType::GetHtmlType(), buffer)) + types->push_back( + base::UTF8ToUTF16(ClipboardFormatType::GetHtmlType().GetName())); + if (IsFormatAvailable(ClipboardFormatType::GetRtfType(), buffer)) + types->push_back( + base::UTF8ToUTF16(ClipboardFormatType::GetRtfType().GetName())); + if (IsFormatAvailable(ClipboardFormatType::GetBitmapType(), buffer)) + types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); + + if (clipboard_internal_->IsFormatAvailable( + ClipboardInternalFormat::kCustom) && + clipboard_internal_->GetData()) { + ReadCustomDataTypes( + clipboard_internal_->GetData()->custom_data_data().c_str(), + clipboard_internal_->GetData()->custom_data_data().size(), types); + } +} + +std::vector +ClipboardNonBacked::ReadAvailablePlatformSpecificFormatNames( + ClipboardBuffer buffer) const { + DCHECK(CalledOnValidThread()); + + std::vector types; + + // Includes all non-pickled AvailableTypes. + if (IsFormatAvailable(ClipboardFormatType::GetPlainTextType(), buffer)) { + types.push_back( + base::UTF8ToUTF16(ClipboardFormatType::GetPlainTextType().GetName())); + } + if (IsFormatAvailable(ClipboardFormatType::GetHtmlType(), buffer)) { + types.push_back( + base::UTF8ToUTF16(ClipboardFormatType::GetHtmlType().GetName())); + } + if (IsFormatAvailable(ClipboardFormatType::GetRtfType(), buffer)) { + types.push_back( + base::UTF8ToUTF16(ClipboardFormatType::GetRtfType().GetName())); + } + if (IsFormatAvailable(ClipboardFormatType::GetBitmapType(), buffer)) { + types.push_back(base::UTF8ToUTF16(kMimeTypePNG)); + } + + return types; +} + +void ClipboardNonBacked::ReadText(ClipboardBuffer buffer, + base::string16* result) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kText); + clipboard_internal_->ReadText(result); +} + +void ClipboardNonBacked::ReadAsciiText(ClipboardBuffer buffer, + std::string* result) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kText); + clipboard_internal_->ReadAsciiText(result); +} + +void ClipboardNonBacked::ReadHTML(ClipboardBuffer buffer, + base::string16* markup, + std::string* src_url, + uint32_t* fragment_start, + uint32_t* fragment_end) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kHtml); + clipboard_internal_->ReadHTML(markup, src_url, fragment_start, fragment_end); +} + +void ClipboardNonBacked::ReadRTF(ClipboardBuffer buffer, + std::string* result) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kRtf); + clipboard_internal_->ReadRTF(result); +} + +void ClipboardNonBacked::ReadImage(ClipboardBuffer buffer, + ReadImageCallback callback) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kImage); + std::move(callback).Run(clipboard_internal_->ReadImage()); +} + +void ClipboardNonBacked::ReadCustomData(ClipboardBuffer buffer, + const base::string16& type, + base::string16* result) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kCustomData); + clipboard_internal_->ReadCustomData(type, result); +} + +void ClipboardNonBacked::ReadBookmark(base::string16* title, + std::string* url) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kBookmark); + clipboard_internal_->ReadBookmark(title, url); +} + +void ClipboardNonBacked::ReadData(const ClipboardFormatType& format, + std::string* result) const { + DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kData); + clipboard_internal_->ReadData(format.GetName(), result); +} + +void ClipboardNonBacked::WritePortableRepresentations( + ClipboardBuffer buffer, + const ObjectMap& objects) { + DCHECK(CalledOnValidThread()); + DCHECK(IsSupportedClipboardBuffer(buffer)); + for (const auto& object : objects) + DispatchPortableRepresentation(object.first, object.second); + ClipboardDataBuilder::CommitToClipboard(clipboard_internal_.get()); +} + +void ClipboardNonBacked::WritePlatformRepresentations( + ClipboardBuffer buffer, + std::vector platform_representations) { + DCHECK(CalledOnValidThread()); + DCHECK(IsSupportedClipboardBuffer(buffer)); + + DispatchPlatformRepresentations(std::move(platform_representations)); + + ClipboardDataBuilder::CommitToClipboard(clipboard_internal_.get()); +} + +void ClipboardNonBacked::WriteText(const char* text_data, size_t text_len) { + ClipboardDataBuilder::WriteText(text_data, text_len); +} + +void ClipboardNonBacked::WriteHTML(const char* markup_data, + size_t markup_len, + const char* url_data, + size_t url_len) { + ClipboardDataBuilder::WriteHTML(markup_data, markup_len, url_data, url_len); +} + +void ClipboardNonBacked::WriteRTF(const char* rtf_data, size_t data_len) { + ClipboardDataBuilder::WriteRTF(rtf_data, data_len); +} + +void ClipboardNonBacked::WriteBookmark(const char* title_data, + size_t title_len, + const char* url_data, + size_t url_len) { + ClipboardDataBuilder::WriteBookmark(title_data, title_len, url_data, url_len); +} + +void ClipboardNonBacked::WriteWebSmartPaste() { + ClipboardDataBuilder::WriteWebSmartPaste(); +} + +void ClipboardNonBacked::WriteBitmap(const SkBitmap& bitmap) { + ClipboardDataBuilder::WriteBitmap(bitmap); +} + +void ClipboardNonBacked::WriteData(const ClipboardFormatType& format, + const char* data_data, + size_t data_len) { + ClipboardDataBuilder::WriteData(format.GetName(), data_data, data_len); +} + +} // namespace ui diff --git a/chromium/ui/base/clipboard/clipboard_non_backed.h b/chromium/ui/base/clipboard/clipboard_non_backed.h new file mode 100644 index 00000000000..8f57aca1e25 --- /dev/null +++ b/chromium/ui/base/clipboard/clipboard_non_backed.h @@ -0,0 +1,86 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_CLIPBOARD_CLIPBOARD_NON_BACKED_H_ +#define UI_BASE_CLIPBOARD_CLIPBOARD_NON_BACKED_H_ + +#include +#include + +#include "base/macros.h" +#include "ui/base/clipboard/clipboard.h" + +namespace ui { + +class ClipboardInternal; + +// In-memory clipboard implementation not backed by an underlying platform. +// This clipboard can be used where there's no need to sync the clipboard with +// an underlying platform, and can substitute platform clipboards like +// ClipboardWin on Windows or ClipboardMac on MacOS. As this isn't backed by an +// underlying platform, the clipboard data isn't persisted after an instance +// goes away. +class ClipboardNonBacked : public Clipboard { + private: + friend class Clipboard; + ClipboardNonBacked(); + ~ClipboardNonBacked() override; + + // Clipboard overrides: + void OnPreShutdown() override; + uint64_t GetSequenceNumber(ClipboardBuffer buffer) const override; + bool IsFormatAvailable(const ClipboardFormatType& format, + ClipboardBuffer buffer) const override; + void Clear(ClipboardBuffer buffer) override; + void ReadAvailableTypes(ClipboardBuffer buffer, + std::vector* types) const override; + std::vector ReadAvailablePlatformSpecificFormatNames( + ClipboardBuffer buffer) const override; + void ReadText(ClipboardBuffer buffer, base::string16* result) const override; + void ReadAsciiText(ClipboardBuffer buffer, + std::string* result) const override; + void ReadHTML(ClipboardBuffer buffer, + base::string16* markup, + std::string* src_url, + uint32_t* fragment_start, + uint32_t* fragment_end) const override; + void ReadRTF(ClipboardBuffer buffer, std::string* result) const override; + void ReadImage(ClipboardBuffer buffer, + ReadImageCallback callback) const override; + void ReadCustomData(ClipboardBuffer buffer, + const base::string16& type, + base::string16* result) const override; + void ReadBookmark(base::string16* title, std::string* url) const override; + void ReadData(const ClipboardFormatType& format, + std::string* result) const override; + void WritePortableRepresentations(ClipboardBuffer buffer, + const ObjectMap& objects) override; + void WritePlatformRepresentations( + ClipboardBuffer buffer, + std::vector platform_representations) + override; + void WriteText(const char* text_data, size_t text_len) override; + void WriteHTML(const char* markup_data, + size_t markup_len, + const char* url_data, + size_t url_len) override; + void WriteRTF(const char* rtf_data, size_t data_len) override; + void WriteBookmark(const char* title_data, + size_t title_len, + const char* url_data, + size_t url_len) override; + void WriteWebSmartPaste() override; + void WriteBitmap(const SkBitmap& bitmap) override; + void WriteData(const ClipboardFormatType& format, + const char* data_data, + size_t data_len) override; + + const std::unique_ptr clipboard_internal_; + + DISALLOW_COPY_AND_ASSIGN(ClipboardNonBacked); +}; + +} // namespace ui + +#endif // UI_BASE_CLIPBOARD_CLIPBOARD_NON_BACKED_H_ diff --git a/chromium/ui/base/clipboard/clipboard_ozone.cc b/chromium/ui/base/clipboard/clipboard_ozone.cc index bb5b7ad7182..a41bc2f5798 100644 --- a/chromium/ui/base/clipboard/clipboard_ozone.cc +++ b/chromium/ui/base/clipboard/clipboard_ozone.cc @@ -15,9 +15,11 @@ #include "base/run_loop.h" #include "base/strings/utf_string_conversions.h" #include "base/timer/timer.h" +#include "build/build_config.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_buffer.h" #include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_monitor.h" #include "ui/base/clipboard/custom_data_helper.h" #include "ui/gfx/codec/png_codec.h" @@ -27,7 +29,7 @@ #if defined(OS_CHROMEOS) && BUILDFLAG(OZONE_PLATFORM_X11) #include "base/command_line.h" -#include "ui/base/clipboard/clipboard_aura.h" +#include "ui/base/clipboard/clipboard_non_backed.h" #include "ui/base/ui_base_switches.h" #endif @@ -294,18 +296,21 @@ class ClipboardOzone::AsyncClipboardOzone { DISALLOW_COPY_AND_ASSIGN(AsyncClipboardOzone); }; +// Uses the factory in the clipboard_linux otherwise. +#if defined(OS_CHROMEOS) || !defined(OS_LINUX) // Clipboard factory method. Clipboard* Clipboard::Create() { -// linux-chromeos uses aura clipboard by default, but supports ozone x11 +// linux-chromeos uses non-backed clipboard by default, but supports ozone x11 // with flag --use-system-clipbboard. #if defined(OS_CHROMEOS) && BUILDFLAG(OZONE_PLATFORM_X11) if (!base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kUseSystemClipboard)) { - return new ClipboardAura; + return new ClipboardNonBacked; } #endif return new ClipboardOzone; } +#endif // ClipboardOzone implementation. ClipboardOzone::ClipboardOzone() { @@ -383,6 +388,7 @@ ClipboardOzone::ReadAvailablePlatformSpecificFormatNames( void ClipboardOzone::ReadText(ClipboardBuffer buffer, base::string16* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kText); auto clipboard_data = async_clipboard_ozone_->ReadClipboardDataAndWait(buffer, kMimeTypeText); @@ -393,6 +399,7 @@ void ClipboardOzone::ReadText(ClipboardBuffer buffer, void ClipboardOzone::ReadAsciiText(ClipboardBuffer buffer, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kText); auto clipboard_data = async_clipboard_ozone_->ReadClipboardDataAndWait(buffer, kMimeTypeText); @@ -405,6 +412,7 @@ void ClipboardOzone::ReadHTML(ClipboardBuffer buffer, uint32_t* fragment_start, uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kHtml); markup->clear(); if (src_url) @@ -423,6 +431,7 @@ void ClipboardOzone::ReadHTML(ClipboardBuffer buffer, void ClipboardOzone::ReadRTF(ClipboardBuffer buffer, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kRtf); auto clipboard_data = async_clipboard_ozone_->ReadClipboardDataAndWait(buffer, kMimeTypeRTF); @@ -431,6 +440,7 @@ void ClipboardOzone::ReadRTF(ClipboardBuffer buffer, void ClipboardOzone::ReadImage(ClipboardBuffer buffer, ReadImageCallback callback) const { + RecordRead(ClipboardFormatMetric::kImage); std::move(callback).Run(ReadImageInternal(buffer)); } @@ -438,6 +448,7 @@ void ClipboardOzone::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, base::string16* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kCustomData); auto custom_data = async_clipboard_ozone_->ReadClipboardDataAndWait( buffer, kMimeTypeWebCustomData); @@ -454,6 +465,7 @@ void ClipboardOzone::ReadBookmark(base::string16* title, void ClipboardOzone::ReadData(const ClipboardFormatType& format, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kData); auto clipboard_data = async_clipboard_ozone_->ReadClipboardDataAndWait( ClipboardBuffer::kCopyPaste, format.GetName()); @@ -469,8 +481,8 @@ void ClipboardOzone::WritePortableRepresentations(ClipboardBuffer buffer, async_clipboard_ozone_->OfferData(buffer); - // Just like Aura/X11 implementation does, copy text data from the copy/paste - // selection to the primary selection. + // Just like Non-Backed/X11 implementation does, copy text data from the + // copy/paste selection to the primary selection. if (buffer == ClipboardBuffer::kCopyPaste) { auto text_iter = objects.find(PortableFormat::kText); if (text_iter != objects.end()) { diff --git a/chromium/ui/base/clipboard/clipboard_test_template.h b/chromium/ui/base/clipboard/clipboard_test_template.h index f31c2594b7d..279252ce350 100644 --- a/chromium/ui/base/clipboard/clipboard_test_template.h +++ b/chromium/ui/base/clipboard/clipboard_test_template.h @@ -46,6 +46,7 @@ #endif #if defined(USE_X11) +#include "ui/base/ui_base_features.h" #include "ui/events/platform/platform_event_source.h" #endif @@ -67,7 +68,8 @@ class ClipboardTest : public PlatformTest { void SetUp() override { PlatformTest::SetUp(); #if defined(USE_X11) - event_source_ = ClipboardTraits::GetEventSource(); + if (!features::IsUsingOzonePlatform()) + event_source_ = ClipboardTraits::GetEventSource(); #endif clipboard_ = ClipboardTraits::Create(); } @@ -653,8 +655,8 @@ TYPED_TEST(ClipboardTest, DataTest) { } // TODO(https://crbug.com/1032161): Implement multiple raw types for -// AuraClipboard. This test currently doesn't run on AuraClipboard because -// AuraClipboard only supports one raw type. +// ClipboardInternal. This test currently doesn't run on ClipboardInternal +// because ClipboardInternal only supports one raw type. #if (!defined(USE_AURA) || defined(OS_WIN) || defined(USE_OZONE) || \ defined(USE_X11)) && \ !defined(OS_CHROMEOS) @@ -739,17 +741,38 @@ TYPED_TEST(ClipboardTest, ReadAvailablePlatformSpecificFormatNamesTest) { #endif } -// Test that a platform-specific write works. +// Test that platform-specific functionality works, with a predefined format in +// On X11 Linux, this test uses a simple MIME type, text/plain. +// On Windows, this test uses a pre-defined ANSI format, CF_TEXT, and tests that +// the Windows implicitly converts this to UNICODE as expected. +#if defined(OS_WIN) || defined(USE_X11) +TYPED_TEST(ClipboardTest, PlatformSpecificDataTest) { + // We're testing platform-specific behavior, so use PlatformClipboardTest. + // TODO(https://crbug.com/1083050): The template shouldn't know about its + // instantiations. Move this information up using a flag, virtual method, or + // creating separate test files for different platforms. + std::string test_suite_name = ::testing::UnitTest::GetInstance() + ->current_test_info() + ->test_suite_name(); + if (test_suite_name != std::string("ClipboardTest/PlatformClipboardTest")) + return; + + const std::string text = "test string"; #if defined(OS_WIN) -TYPED_TEST(ClipboardTest, WindowsPredefinedFormatWriteDataTest) { + // Windows pre-defined ANSI text format. const std::string kFormatString = "CF_TEXT"; - const std::string text = "test string"; + // Windows requires an extra '\0' at the end for a raw write. + const std::string kPlatformSpecificText = text + '\0'; +#elif defined(USE_X11) + const std::string kFormatString = "text/plain"; // X11 text format + const std::string kPlatformSpecificText = text; +#endif base::span text_span( - reinterpret_cast(text.data()), text.size() + 1); - + reinterpret_cast(kPlatformSpecificText.data()), + kPlatformSpecificText.size()); { ScopedClipboardWriter clipboard_writer(ClipboardBuffer::kCopyPaste); - clipboard_writer.WriteData(UTF8ToUTF16(kFormatString), + clipboard_writer.WriteData(ASCIIToUTF16(kFormatString), mojo_base::BigBuffer(text_span)); } @@ -758,27 +781,32 @@ TYPED_TEST(ClipboardTest, WindowsPredefinedFormatWriteDataTest) { ClipboardBuffer::kCopyPaste); EXPECT_THAT(raw_types, Contains(ASCIIToUTF16(kFormatString))); + +#if defined(OS_WIN) + // Only Windows ClipboardFormatType recognizes ANSI formats. EXPECT_TRUE(this->clipboard().IsFormatAvailable( ClipboardFormatType::GetPlainTextAType(), ClipboardBuffer::kCopyPaste)); +#endif // defined(OS_WIN) - // Only ClipboardWin recognizes the Windows-specific CF_TEXT. - std::string test_suite_name = ::testing::UnitTest::GetInstance() - ->current_test_info() - ->test_suite_name(); - if (test_suite_name == std::string("ClipboardTest/PlatformClipboardTest")) { - std::string text_result; - this->clipboard().ReadAsciiText(ClipboardBuffer::kCopyPaste, &text_result); - EXPECT_EQ(text, text_result); - - // Windows will automatically convert CF_TEXT to its UNICODE version. - EXPECT_TRUE(this->clipboard().IsFormatAvailable( - ClipboardFormatType::GetPlainTextType(), ClipboardBuffer::kCopyPaste)); - base::string16 text_result16; - this->clipboard().ReadText(ClipboardBuffer::kCopyPaste, &text_result16); - EXPECT_EQ(base::ASCIIToUTF16(text), text_result16); - } + EXPECT_TRUE(this->clipboard().IsFormatAvailable( + ClipboardFormatType::GetPlainTextType(), ClipboardBuffer::kCopyPaste)); + + std::string text_result; + this->clipboard().ReadAsciiText(ClipboardBuffer::kCopyPaste, &text_result); + EXPECT_EQ(text_result, text); + // Note: Windows will automatically convert CF_TEXT to its UNICODE version. + EXPECT_TRUE(this->clipboard().IsFormatAvailable( + ClipboardFormatType::GetPlainTextType(), ClipboardBuffer::kCopyPaste)); + base::string16 text_result16; + this->clipboard().ReadText(ClipboardBuffer::kCopyPaste, &text_result16); + EXPECT_EQ(text_result16, base::ASCIIToUTF16(text)); + + std::string platform_specific_result; + this->clipboard().ReadData(ClipboardFormatType::GetType(kFormatString), + &platform_specific_result); + EXPECT_EQ(platform_specific_result, kPlatformSpecificText); } -#endif +#endif // defined(OS_WIN) || defined(USE_X11) #if !defined(OS_MACOSX) && !defined(OS_ANDROID) TYPED_TEST(ClipboardTest, HyperlinkTest) { diff --git a/chromium/ui/base/clipboard/clipboard_util_mac.mm b/chromium/ui/base/clipboard/clipboard_util_mac.mm index a748d4af65a..8db45d20a2a 100644 --- a/chromium/ui/base/clipboard/clipboard_util_mac.mm +++ b/chromium/ui/base/clipboard/clipboard_util_mac.mm @@ -7,6 +7,7 @@ #include "base/mac/foundation_util.h" #import "base/mac/mac_util.h" #include "base/mac/scoped_cftyperef.h" +#include "base/notreached.h" namespace ui { diff --git a/chromium/ui/base/clipboard/clipboard_win.cc b/chromium/ui/base/clipboard/clipboard_win.cc index 9bfabd34eab..421f22eaaf6 100644 --- a/chromium/ui/base/clipboard/clipboard_win.cc +++ b/chromium/ui/base/clipboard/clipboard_win.cc @@ -30,6 +30,7 @@ #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_util_win.h" #include "ui/base/clipboard/custom_data_helper.h" #include "ui/gfx/canvas.h" @@ -319,6 +320,7 @@ ClipboardWin::ReadAvailablePlatformSpecificFormatNames( void ClipboardWin::ReadText(ClipboardBuffer buffer, base::string16* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kText); if (!result) { NOTREACHED(); return; @@ -344,6 +346,7 @@ void ClipboardWin::ReadText(ClipboardBuffer buffer, void ClipboardWin::ReadAsciiText(ClipboardBuffer buffer, std::string* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kText); if (!result) { NOTREACHED(); return; @@ -372,6 +375,7 @@ void ClipboardWin::ReadHTML(ClipboardBuffer buffer, uint32_t* fragment_start, uint32_t* fragment_end) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kHtml); markup->clear(); // TODO(dcheng): Remove these checks, I don't think they should be optional. @@ -425,6 +429,7 @@ void ClipboardWin::ReadHTML(ClipboardBuffer buffer, void ClipboardWin::ReadRTF(ClipboardBuffer buffer, std::string* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kRtf); ReadData(ClipboardFormatType::GetRtfType(), result); TrimAfterNull(result); @@ -432,6 +437,7 @@ void ClipboardWin::ReadRTF(ClipboardBuffer buffer, std::string* result) const { void ClipboardWin::ReadImage(ClipboardBuffer buffer, ReadImageCallback callback) const { + RecordRead(ClipboardFormatMetric::kImage); std::move(callback).Run(ReadImageInternal(buffer)); } @@ -439,6 +445,7 @@ void ClipboardWin::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, base::string16* result) const { DCHECK_EQ(buffer, ClipboardBuffer::kCopyPaste); + RecordRead(ClipboardFormatMetric::kCustomData); // Acquire the clipboard. ScopedClipboard clipboard; @@ -455,6 +462,7 @@ void ClipboardWin::ReadCustomData(ClipboardBuffer buffer, } void ClipboardWin::ReadBookmark(base::string16* title, std::string* url) const { + RecordRead(ClipboardFormatMetric::kBookmark); if (title) title->clear(); @@ -481,6 +489,7 @@ void ClipboardWin::ReadBookmark(base::string16* title, std::string* url) const { void ClipboardWin::ReadData(const ClipboardFormatType& format, std::string* result) const { + RecordRead(ClipboardFormatMetric::kData); if (!result) { NOTREACHED(); return; diff --git a/chromium/ui/base/clipboard/clipboard_x11.cc b/chromium/ui/base/clipboard/clipboard_x11.cc index 95e2caff21a..c2f3620584b 100644 --- a/chromium/ui/base/clipboard/clipboard_x11.cc +++ b/chromium/ui/base/clipboard/clipboard_x11.cc @@ -22,8 +22,10 @@ #include "base/strings/utf_string_conversions.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/clipboard/clipboard_constants.h" +#include "ui/base/clipboard/clipboard_metrics.h" #include "ui/base/clipboard/clipboard_monitor.h" #include "ui/base/clipboard/custom_data_helper.h" +#include "ui/base/nine_image_painter_factory.h" #include "ui/base/x/selection_owner.h" #include "ui/base/x/selection_requestor.h" #include "ui/base/x/selection_utils.h" @@ -32,8 +34,12 @@ #include "ui/events/x/x11_window_event_manager.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/geometry/size.h" +#include "ui/gfx/x/connection.h" +#include "ui/gfx/x/event.h" #include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" +#include "ui/gfx/x/xfixes.h" +#include "ui/gfx/x/xproto.h" namespace ui { @@ -61,63 +67,57 @@ class SelectionChangeObserver : public XEventObserver { ~SelectionChangeObserver() override; // XEventObserver: - void WillProcessXEvent(XEvent* xev) override; - void DidProcessXEvent(XEvent* xev) override {} + void WillProcessXEvent(x11::Event* xev) override; + void DidProcessXEvent(x11::Event* xev) override {} - int event_base_; - Atom clipboard_atom_; - uint64_t clipboard_sequence_number_; - uint64_t primary_sequence_number_; + x11::Atom clipboard_atom_{}; + uint64_t clipboard_sequence_number_{}; + uint64_t primary_sequence_number_{}; DISALLOW_COPY_AND_ASSIGN(SelectionChangeObserver); }; -SelectionChangeObserver::SelectionChangeObserver() - : event_base_(-1), - clipboard_atom_(x11::None), - clipboard_sequence_number_(0), - primary_sequence_number_(0) { - int ignored; - if (XFixesQueryExtension(gfx::GetXDisplay(), &event_base_, &ignored)) { - clipboard_atom_ = gfx::GetAtom(kClipboard); - XFixesSelectSelectionInput(gfx::GetXDisplay(), GetX11RootWindow(), - clipboard_atom_, - XFixesSetSelectionOwnerNotifyMask | - XFixesSelectionWindowDestroyNotifyMask | - XFixesSelectionClientCloseNotifyMask); - // This seems to be semi-optional. For some reason, registering for any - // selection notify events seems to subscribe us to events for both the - // primary and the clipboard buffers. Register anyway just to be safe. - XFixesSelectSelectionInput(gfx::GetXDisplay(), GetX11RootWindow(), - XA_PRIMARY, - XFixesSetSelectionOwnerNotifyMask | - XFixesSelectionWindowDestroyNotifyMask | - XFixesSelectionClientCloseNotifyMask); - - X11EventSource::GetInstance()->AddXEventObserver(this); - } -} +SelectionChangeObserver::SelectionChangeObserver() { + auto& xfixes = x11::Connection::Get()->xfixes(); + // Let the server know the client version. No need to sync since we don't + // care what version is running on the server. + xfixes.QueryVersion({x11::XFixes::major_version, x11::XFixes::minor_version}); + if (!xfixes.present()) + return; + + clipboard_atom_ = gfx::GetAtom(kClipboard); + auto mask = x11::XFixes::SelectionEventMask::SetSelectionOwner | + x11::XFixes::SelectionEventMask::SelectionWindowDestroy | + x11::XFixes::SelectionEventMask::SelectionClientClose; + xfixes.SelectSelectionInput({GetX11RootWindow(), clipboard_atom_, mask}); + // This seems to be semi-optional. For some reason, registering for any + // selection notify events seems to subscribe us to events for both the + // primary and the clipboard buffers. Register anyway just to be safe. + xfixes.SelectSelectionInput({GetX11RootWindow(), x11::Atom::PRIMARY, mask}); -SelectionChangeObserver::~SelectionChangeObserver() { - // We are a singleton; we will outlive the event source. + X11EventSource::GetInstance()->AddXEventObserver(this); } +// We are a singleton; we will outlive the event source. +SelectionChangeObserver::~SelectionChangeObserver() = default; + SelectionChangeObserver* SelectionChangeObserver::GetInstance() { return base::Singleton::get(); } -void SelectionChangeObserver::WillProcessXEvent(XEvent* xev) { - if (xev->type == event_base_ + XFixesSelectionNotify) { - XFixesSelectionNotifyEvent* ev = - reinterpret_cast(xev); - if (ev->selection == clipboard_atom_) { - clipboard_sequence_number_++; - ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); - } else if (ev->selection == XA_PRIMARY) { - primary_sequence_number_++; - } else { - DLOG(ERROR) << "Unexpected selection atom: " << ev->selection; - } +void SelectionChangeObserver::WillProcessXEvent(x11::Event* xev) { + auto* ev = xev->As(); + if (!ev) + return; + + if (static_cast(ev->selection) == clipboard_atom_) { + clipboard_sequence_number_++; + ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); + } else if (ev->selection == x11::Atom::PRIMARY) { + primary_sequence_number_++; + } else { + DLOG(ERROR) << "Unexpected selection atom: " + << static_cast(ev->selection); } } @@ -126,7 +126,7 @@ void SelectionChangeObserver::WillProcessXEvent(XEvent* xev) { // Represents a list of possible return types. Copy constructable. class TargetList { public: - using AtomVector = std::vector<::Atom>; + using AtomVector = std::vector; explicit TargetList(const AtomVector& target_list); @@ -134,7 +134,7 @@ class TargetList { bool ContainsText() const; bool ContainsFormat(const ClipboardFormatType& format_type) const; - bool ContainsAtom(::Atom atom) const; + bool ContainsAtom(x11::Atom atom) const; private: AtomVector target_list_; @@ -144,7 +144,7 @@ TargetList::TargetList(const AtomVector& target_list) : target_list_(target_list) {} bool TargetList::ContainsText() const { - std::vector<::Atom> atoms = GetTextAtomsFrom(); + std::vector atoms = GetTextAtomsFrom(); for (const auto& atom : atoms) { if (ContainsAtom(atom)) return true; @@ -154,14 +154,19 @@ bool TargetList::ContainsText() const { } bool TargetList::ContainsFormat(const ClipboardFormatType& format_type) const { - ::Atom atom = gfx::GetAtom(format_type.GetName().c_str()); + x11::Atom atom = gfx::GetAtom(format_type.GetName().c_str()); return ContainsAtom(atom); } -bool TargetList::ContainsAtom(::Atom atom) const { +bool TargetList::ContainsAtom(x11::Atom atom) const { return base::Contains(target_list_, atom); } +x11::Window GetSelectionOwner(x11::Atom selection) { + auto response = x11::Connection::Get()->GetSelectionOwner({selection}).Sync(); + return response ? response->owner : x11::Window::None; +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -176,14 +181,14 @@ class ClipboardX11::X11Details : public XEventDispatcher { // Returns the X11 selection atom that we pass to various XSelection functions // for the given buffer. - ::Atom LookupSelectionForClipboardBuffer(ClipboardBuffer buffer) const; + x11::Atom LookupSelectionForClipboardBuffer(ClipboardBuffer buffer) const; // Returns the X11 selection atom that we pass to various XSelection functions // for ClipboardBuffer::kCopyPaste. - ::Atom GetCopyPasteSelection() const; + x11::Atom GetCopyPasteSelection() const; // Finds the SelectionFormatMap for the incoming selection atom. - const SelectionFormatMap& LookupStorageForAtom(::Atom atom); + const SelectionFormatMap& LookupStorageForAtom(x11::Atom atom); // As we need to collect all the data types before we tell X11 that we own a // particular selection, we create a temporary clipboard mapping that @@ -208,7 +213,7 @@ class ClipboardX11::X11Details : public XEventDispatcher { // and do the asynchronous dance with whatever application is holding the // selection. SelectionData RequestAndWaitForTypes(ClipboardBuffer buffer, - const std::vector<::Atom>& types); + const std::vector& types); // Retrieves the list of possible data types the current clipboard owner has. // @@ -217,10 +222,10 @@ class ClipboardX11::X11Details : public XEventDispatcher { TargetList WaitAndGetTargetsList(ClipboardBuffer buffer); // Returns a list of all text atoms that we handle. - std::vector<::Atom> GetTextAtoms() const; + std::vector GetTextAtoms() const; // Returns a vector with a |format| converted to an X11 atom. - std::vector<::Atom> GetAtomsForFormat(const ClipboardFormatType& format); + std::vector GetAtomsForFormat(const ClipboardFormatType& format); // Clears a certain clipboard buffer, whether we own it or not. void Clear(ClipboardBuffer buffer); @@ -231,16 +236,14 @@ class ClipboardX11::X11Details : public XEventDispatcher { private: // XEventDispatcher: - bool DispatchXEvent(XEvent* xev) override; - - bool CanDispatchXEvent(XEvent* xev); + bool DispatchXEvent(x11::Event* xev) override; // Our X11 state. - Display* x_display_; - ::Window x_root_window_; + x11::Connection* connection_; + x11::Window x_root_window_; // Input-only window used as a selection owner. - ::Window x_window_; + x11::Window x_window_; // Events selected on |x_window_|. std::unique_ptr x_window_events_; @@ -259,26 +262,16 @@ class ClipboardX11::X11Details : public XEventDispatcher { }; ClipboardX11::X11Details::X11Details() - : x_display_(gfx::GetXDisplay()), - x_root_window_(DefaultRootWindow(x_display_)), - x_window_(XCreateWindow(x_display_, - x_root_window_, - -100, - -100, - 10, - 10, // x, y, width, height - 0, // border width - CopyFromParent, // depth - InputOnly, - CopyFromParent, // visual - 0, - nullptr)), - selection_requestor_(x_display_, x_window_, this), - clipboard_owner_(x_display_, x_window_, gfx::GetAtom(kClipboard)), - primary_owner_(x_display_, x_window_, XA_PRIMARY) { - XStoreName(x_display_, x_window_, "Chromium clipboard"); - x_window_events_.reset( - new XScopedEventSelector(x_window_, PropertyChangeMask)); + : connection_(x11::Connection::Get()), + x_root_window_(ui::GetX11RootWindow()), + x_window_(CreateDummyWindow("Chromium Clipboard Window")), + selection_requestor_(x_window_, this), + clipboard_owner_(connection_, x_window_, gfx::GetAtom(kClipboard)), + primary_owner_(connection_, x_window_, x11::Atom::PRIMARY) { + SetStringProperty(x_window_, x11::Atom::WM_NAME, x11::Atom::STRING, + "Chromium clipboard"); + x_window_events_ = + std::make_unique(x_window_, PropertyChangeMask); if (X11EventSource::GetInstance()) X11EventSource::GetInstance()->AddXEventDispatcher(this); @@ -288,24 +281,24 @@ ClipboardX11::X11Details::~X11Details() { if (X11EventSource::GetInstance()) X11EventSource::GetInstance()->RemoveXEventDispatcher(this); - XDestroyWindow(x_display_, x_window_); + connection_->DestroyWindow({x_window_}); } -::Atom ClipboardX11::X11Details::LookupSelectionForClipboardBuffer( +x11::Atom ClipboardX11::X11Details::LookupSelectionForClipboardBuffer( ClipboardBuffer buffer) const { if (buffer == ClipboardBuffer::kCopyPaste) return GetCopyPasteSelection(); - return XA_PRIMARY; + return x11::Atom::PRIMARY; } -::Atom ClipboardX11::X11Details::GetCopyPasteSelection() const { +x11::Atom ClipboardX11::X11Details::GetCopyPasteSelection() const { return gfx::GetAtom(kClipboard); } const SelectionFormatMap& ClipboardX11::X11Details::LookupStorageForAtom( - ::Atom atom) { - if (atom == XA_PRIMARY) + x11::Atom atom) { + if (atom == x11::Atom::PRIMARY) return primary_owner_.selection_format_map(); DCHECK_EQ(GetCopyPasteSelection(), atom); @@ -319,7 +312,7 @@ void ClipboardX11::X11Details::CreateNewClipboardData() { void ClipboardX11::X11Details::InsertMapping( const std::string& key, const scoped_refptr& memory) { - ::Atom atom_key = gfx::GetAtom(key.c_str()); + x11::Atom atom_key = gfx::GetAtom(key.c_str()); clipboard_data_.Insert(atom_key, memory); } @@ -333,9 +326,9 @@ void ClipboardX11::X11Details::TakeOwnershipOfSelection( SelectionData ClipboardX11::X11Details::RequestAndWaitForTypes( ClipboardBuffer buffer, - const std::vector<::Atom>& types) { - ::Atom selection_name = LookupSelectionForClipboardBuffer(buffer); - if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { + const std::vector& types) { + x11::Atom selection_name = LookupSelectionForClipboardBuffer(buffer); + if (GetSelectionOwner(selection_name) == x_window_) { // We can local fastpath instead of playing the nested run loop game // with the X server. const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); @@ -348,8 +341,8 @@ SelectionData ClipboardX11::X11Details::RequestAndWaitForTypes( } else { TargetList targets = WaitAndGetTargetsList(buffer); - ::Atom selection_name = LookupSelectionForClipboardBuffer(buffer); - std::vector<::Atom> intersection; + x11::Atom selection_name = LookupSelectionForClipboardBuffer(buffer); + std::vector intersection; GetAtomIntersection(types, targets.target_list(), &intersection); return selection_requestor_.RequestAndWaitForTypes(selection_name, intersection); @@ -360,27 +353,25 @@ SelectionData ClipboardX11::X11Details::RequestAndWaitForTypes( TargetList ClipboardX11::X11Details::WaitAndGetTargetsList( ClipboardBuffer buffer) { - ::Atom selection_name = LookupSelectionForClipboardBuffer(buffer); - std::vector<::Atom> out; - if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { + x11::Atom selection_name = LookupSelectionForClipboardBuffer(buffer); + std::vector out; + if (GetSelectionOwner(selection_name) == x_window_) { // We can local fastpath and return the list of local targets. const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); for (const auto& format : format_map) out.push_back(format.first); } else { - scoped_refptr data; - size_t out_data_items = 0; - ::Atom out_type = x11::None; + std::vector data; + x11::Atom out_type = x11::Atom::None; if (selection_requestor_.PerformBlockingConvertSelection( - selection_name, gfx::GetAtom(kTargets), &data, &out_data_items, - &out_type)) { + selection_name, gfx::GetAtom(kTargets), &data, &out_type)) { // Some apps return an |out_type| of "TARGETS". (crbug.com/377893) - if (out_type == XA_ATOM || out_type == gfx::GetAtom(kTargets)) { - const ::Atom* atom_array = - reinterpret_cast(data->front()); - for (size_t i = 0; i < out_data_items; ++i) + if (out_type == x11::Atom::ATOM || out_type == gfx::GetAtom(kTargets)) { + const x11::Atom* atom_array = + reinterpret_cast(data.data()); + for (size_t i = 0; i < data.size() / sizeof(x11::Atom); ++i) out.push_back(atom_array[i]); } } else { @@ -390,11 +381,11 @@ TargetList ClipboardX11::X11Details::WaitAndGetTargetsList( // text. This is pretty unfortunate since it means we have to actually // copy the data to see if it is available, but at least this path // shouldn't be hit for conforming programs. - std::vector<::Atom> types = GetTextAtoms(); + std::vector types = GetTextAtoms(); for (const auto& text_atom : types) { - ::Atom type = x11::None; + x11::Atom type = x11::Atom::None; if (selection_requestor_.PerformBlockingConvertSelection( - selection_name, text_atom, nullptr, nullptr, &type) && + selection_name, text_atom, nullptr, &type) && type == text_atom) { out.push_back(text_atom); } @@ -405,11 +396,11 @@ TargetList ClipboardX11::X11Details::WaitAndGetTargetsList( return TargetList(out); } -std::vector<::Atom> ClipboardX11::X11Details::GetTextAtoms() const { +std::vector ClipboardX11::X11Details::GetTextAtoms() const { return GetTextAtomsFrom(); } -std::vector<::Atom> ClipboardX11::X11Details::GetAtomsForFormat( +std::vector ClipboardX11::X11Details::GetAtomsForFormat( const ClipboardFormatType& format) { return {gfx::GetAtom(format.GetName().c_str())}; } @@ -422,18 +413,18 @@ void ClipboardX11::X11Details::Clear(ClipboardBuffer buffer) { } void ClipboardX11::X11Details::StoreCopyPasteDataAndWait() { - ::Atom selection = GetCopyPasteSelection(); - if (XGetSelectionOwner(x_display_, selection) != x_window_) + x11::Atom selection = GetCopyPasteSelection(); + if (GetSelectionOwner(selection) != x_window_) return; - ::Atom clipboard_manager_atom = gfx::GetAtom(kClipboardManager); - if (XGetSelectionOwner(x_display_, clipboard_manager_atom) == x11::None) + x11::Atom clipboard_manager_atom = gfx::GetAtom(kClipboardManager); + if (GetSelectionOwner(clipboard_manager_atom) == x11::Window::None) return; const SelectionFormatMap& format_map = LookupStorageForAtom(selection); if (format_map.size() == 0) return; - std::vector targets = format_map.GetTypes(); + std::vector targets = format_map.GetTypes(); base::TimeTicks start = base::TimeTicks::Now(); selection_requestor_.PerformBlockingConvertSelectionWithParameter( @@ -442,70 +433,44 @@ void ClipboardX11::X11Details::StoreCopyPasteDataAndWait() { base::TimeTicks::Now() - start); } -bool ClipboardX11::X11Details::CanDispatchXEvent(XEvent* xev) { - if (xev->xany.window == x_window_) - return true; - - if (xev->type == PropertyNotify) { - return primary_owner_.CanDispatchPropertyEvent(*xev) || - clipboard_owner_.CanDispatchPropertyEvent(*xev) || - selection_requestor_.CanDispatchPropertyEvent(*xev); - } - return false; -} - -bool ClipboardX11::X11Details::DispatchXEvent(XEvent* xev) { - if (!CanDispatchXEvent(xev)) - return false; - - switch (xev->type) { - case SelectionRequest: { - if (xev->xselectionrequest.selection == XA_PRIMARY) { - primary_owner_.OnSelectionRequest(*xev); - } else { - // We should not get requests for the CLIPBOARD_MANAGER selection - // because we never take ownership of it. - DCHECK_EQ(GetCopyPasteSelection(), xev->xselectionrequest.selection); - clipboard_owner_.OnSelectionRequest(*xev); - } - break; - } - case SelectionNotify: { - selection_requestor_.OnSelectionNotify(*xev); - break; - } - case SelectionClear: { - if (xev->xselectionclear.selection == XA_PRIMARY) { - primary_owner_.OnSelectionClear(*xev); - } else { - // We should not get requests for the CLIPBOARD_MANAGER selection - // because we never take ownership of it. - DCHECK_EQ(GetCopyPasteSelection(), xev->xselection.selection); - clipboard_owner_.OnSelectionClear(*xev); - } - break; +bool ClipboardX11::X11Details::DispatchXEvent(x11::Event* xev) { + if (auto* request = xev->As()) { + if (request->owner != x_window_) + return false; + if (request->selection == x11::Atom::PRIMARY) { + primary_owner_.OnSelectionRequest(*xev); + } else { + // We should not get requests for the CLIPBOARD_MANAGER selection + // because we never take ownership of it. + DCHECK_EQ(GetCopyPasteSelection(), request->selection); + clipboard_owner_.OnSelectionRequest(*xev); } - case PropertyNotify: { - if (primary_owner_.CanDispatchPropertyEvent(*xev)) - primary_owner_.OnPropertyEvent(*xev); - if (clipboard_owner_.CanDispatchPropertyEvent(*xev)) - clipboard_owner_.OnPropertyEvent(*xev); - if (selection_requestor_.CanDispatchPropertyEvent(*xev)) - selection_requestor_.OnPropertyEvent(*xev); - break; + } else if (auto* notify = xev->As()) { + if (notify->requestor != x_window_) + return false; + selection_requestor_.OnSelectionNotify(*notify); + } else if (auto* clear = xev->As()) { + if (clear->owner != x_window_) + return false; + if (clear->selection == x11::Atom::PRIMARY) { + primary_owner_.OnSelectionClear(*xev); + } else { + // We should not get requests for the CLIPBOARD_MANAGER selection + // because we never take ownership of it. + DCHECK_EQ(GetCopyPasteSelection(), clear->selection); + clipboard_owner_.OnSelectionClear(*xev); } - default: - break; + } else if (auto* prop = xev->As()) { + if (primary_owner_.CanDispatchPropertyEvent(*xev)) + primary_owner_.OnPropertyEvent(*xev); + if (clipboard_owner_.CanDispatchPropertyEvent(*xev)) + clipboard_owner_.OnPropertyEvent(*xev); + if (selection_requestor_.CanDispatchPropertyEvent(*xev)) + selection_requestor_.OnPropertyEvent(*xev); } return false; } -/////////////////////////////////////////////////////////////////////////////// -// Clipboard factory method. -Clipboard* Clipboard::Create() { - return new ClipboardX11; -} - /////////////////////////////////////////////////////////////////////////////// // ClipboardX11 @@ -586,17 +551,16 @@ ClipboardX11::ReadAvailablePlatformSpecificFormatNames( if (target_list.empty()) return {}; - std::vector types_buffer(target_list.size()); - // Call XGetAtomNames to minimize trips to the X11 server. - int status = XGetAtomNames(gfx::GetXDisplay(), target_list.data(), - target_list.size(), types_buffer.data()); - DCHECK(status) << "XGetAtomNames failed! An invalid Atom was passed in."; - + std::vector> futures; + for (x11::Atom target : target_list) + futures.push_back(x11::Connection::Get()->GetAtomName({target})); std::vector types; types.reserve(target_list.size()); - for (char* type : types_buffer) { - types.push_back(base::UTF8ToUTF16(type)); - XFree(type); + for (auto& future : futures) { + if (auto response = future.Sync()) + types.push_back(base::UTF8ToUTF16(response->name)); + else + types.emplace_back(); } return types; @@ -605,6 +569,7 @@ ClipboardX11::ReadAvailablePlatformSpecificFormatNames( void ClipboardX11::ReadText(ClipboardBuffer buffer, base::string16* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kText); SelectionData data(x11_details_->RequestAndWaitForTypes( buffer, x11_details_->GetTextAtoms())); @@ -617,6 +582,7 @@ void ClipboardX11::ReadText(ClipboardBuffer buffer, void ClipboardX11::ReadAsciiText(ClipboardBuffer buffer, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kText); SelectionData data(x11_details_->RequestAndWaitForTypes( buffer, x11_details_->GetTextAtoms())); @@ -632,6 +598,7 @@ void ClipboardX11::ReadHTML(ClipboardBuffer buffer, uint32_t* fragment_start, uint32_t* fragment_end) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kHtml); markup->clear(); if (src_url) src_url->clear(); @@ -652,6 +619,7 @@ void ClipboardX11::ReadHTML(ClipboardBuffer buffer, void ClipboardX11::ReadRTF(ClipboardBuffer buffer, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kRtf); SelectionData data(x11_details_->RequestAndWaitForTypes( buffer, @@ -663,6 +631,7 @@ void ClipboardX11::ReadRTF(ClipboardBuffer buffer, std::string* result) const { void ClipboardX11::ReadImage(ClipboardBuffer buffer, ReadImageCallback callback) const { DCHECK(IsSupportedClipboardBuffer(buffer)); + RecordRead(ClipboardFormatMetric::kImage); std::move(callback).Run(ReadImageInternal(buffer)); } @@ -670,6 +639,7 @@ void ClipboardX11::ReadCustomData(ClipboardBuffer buffer, const base::string16& type, base::string16* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kCustomData); SelectionData data(x11_details_->RequestAndWaitForTypes( buffer, x11_details_->GetAtomsForFormat( @@ -687,6 +657,7 @@ void ClipboardX11::ReadBookmark(base::string16* title, std::string* url) const { void ClipboardX11::ReadData(const ClipboardFormatType& format, std::string* result) const { DCHECK(CalledOnValidThread()); + RecordRead(ClipboardFormatMetric::kData); SelectionData data(x11_details_->RequestAndWaitForTypes( ClipboardBuffer::kCopyPaste, x11_details_->GetAtomsForFormat(format))); diff --git a/chromium/ui/base/clipboard/scoped_clipboard_writer.cc b/chromium/ui/base/clipboard/scoped_clipboard_writer.cc index 1b8312f5fc5..c723b0d2e33 100644 --- a/chromium/ui/base/clipboard/scoped_clipboard_writer.cc +++ b/chromium/ui/base/clipboard/scoped_clipboard_writer.cc @@ -8,6 +8,7 @@ #include "base/strings/utf_string_conversions.h" #include "net/base/escape.h" #include "ui/base/clipboard/clipboard_format_type.h" +#include "ui/base/clipboard/clipboard_metrics.h" #include "ui/gfx/geometry/size.h" // Documentation on the format of the parameters for each clipboard target can @@ -31,9 +32,12 @@ ScopedClipboardWriter::~ScopedClipboardWriter() { Clipboard::GetForCurrentThread()->WritePlatformRepresentations( buffer_, std::move(platform_representations_)); } + if (confidential_) + Clipboard::GetForCurrentThread()->MarkAsConfidential(); } void ScopedClipboardWriter::WriteText(const base::string16& text) { + RecordWrite(ClipboardFormatMetric::kText); std::string utf8_text = base::UTF16ToUTF8(text); Clipboard::ObjectMapParams parameters; @@ -44,6 +48,7 @@ void ScopedClipboardWriter::WriteText(const base::string16& text) { void ScopedClipboardWriter::WriteHTML(const base::string16& markup, const std::string& source_url) { + RecordWrite(ClipboardFormatMetric::kHtml); std::string utf8_markup = base::UTF16ToUTF8(markup); Clipboard::ObjectMapParams parameters; @@ -59,6 +64,7 @@ void ScopedClipboardWriter::WriteHTML(const base::string16& markup, } void ScopedClipboardWriter::WriteRTF(const std::string& rtf_data) { + RecordWrite(ClipboardFormatMetric::kRtf); Clipboard::ObjectMapParams parameters; parameters.push_back(Clipboard::ObjectMapParam(rtf_data.begin(), rtf_data.end())); @@ -69,6 +75,7 @@ void ScopedClipboardWriter::WriteBookmark(const base::string16& bookmark_title, const std::string& url) { if (bookmark_title.empty() || url.empty()) return; + RecordWrite(ClipboardFormatMetric::kBookmark); std::string utf8_markup = base::UTF16ToUTF8(bookmark_title); @@ -94,6 +101,7 @@ void ScopedClipboardWriter::WriteHyperlink(const base::string16& anchor_text, } void ScopedClipboardWriter::WriteWebSmartPaste() { + RecordWrite(ClipboardFormatMetric::kWebSmartPaste); objects_[Clipboard::PortableFormat::kWebkit] = Clipboard::ObjectMapParams(); } @@ -101,6 +109,7 @@ void ScopedClipboardWriter::WriteImage(const SkBitmap& bitmap) { if (bitmap.drawsNothing()) return; DCHECK(bitmap.getPixels()); + RecordWrite(ClipboardFormatMetric::kImage); bitmap_ = bitmap; // TODO(dcheng): This is slightly less horrible than what we used to do, but @@ -114,9 +123,14 @@ void ScopedClipboardWriter::WriteImage(const SkBitmap& bitmap) { objects_[Clipboard::PortableFormat::kBitmap] = parameters; } +void ScopedClipboardWriter::MarkAsConfidential() { + confidential_ = true; +} + void ScopedClipboardWriter::WritePickledData( const base::Pickle& pickle, const ClipboardFormatType& format) { + RecordWrite(ClipboardFormatMetric::kCustomData); std::string format_string = format.Serialize(); Clipboard::ObjectMapParam format_parameter(format_string.begin(), format_string.end()); @@ -134,6 +148,7 @@ void ScopedClipboardWriter::WritePickledData( void ScopedClipboardWriter::WriteData(const base::string16& format, mojo_base::BigBuffer data) { + RecordWrite(ClipboardFormatMetric::kData); platform_representations_.push_back( {base::UTF16ToUTF8(format), std::move(data)}); } @@ -142,6 +157,7 @@ void ScopedClipboardWriter::Reset() { objects_.clear(); platform_representations_.clear(); bitmap_.reset(); + confidential_ = false; } } // namespace ui diff --git a/chromium/ui/base/clipboard/scoped_clipboard_writer.h b/chromium/ui/base/clipboard/scoped_clipboard_writer.h index d0e5cfb3e3e..d2ed3736ce2 100644 --- a/chromium/ui/base/clipboard/scoped_clipboard_writer.h +++ b/chromium/ui/base/clipboard/scoped_clipboard_writer.h @@ -67,6 +67,9 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ScopedClipboardWriter { void WriteImage(const SkBitmap& bitmap); + // Mark the data to be written as confidential. + void MarkAsConfidential(); + // Removes all objects that would be written to the clipboard. void Reset(); @@ -83,6 +86,8 @@ class COMPONENT_EXPORT(UI_BASE_CLIPBOARD) ScopedClipboardWriter { SkBitmap bitmap_; + bool confidential_ = false; + DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); }; diff --git a/chromium/ui/base/cocoa/accessibility_focus_overrider.h b/chromium/ui/base/cocoa/accessibility_focus_overrider.h index d8b6def31a2..7d3b88d04a7 100644 --- a/chromium/ui/base/cocoa/accessibility_focus_overrider.h +++ b/chromium/ui/base/cocoa/accessibility_focus_overrider.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_COCOA_ACCESSIBILITY_FOCUS_OVERRIDER_H_ #define UI_BASE_COCOA_ACCESSIBILITY_FOCUS_OVERRIDER_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -28,7 +28,7 @@ namespace ui { // The above-required overriding of focus is done by instantiating an // AccessibilityFocusOverrider and updating its state when the NSView in the // PWA process is focused. -class UI_BASE_EXPORT AccessibilityFocusOverrider { +class COMPONENT_EXPORT(UI_BASE) AccessibilityFocusOverrider { public: class Client { public: diff --git a/chromium/ui/base/cocoa/appkit_utils.h b/chromium/ui/base/cocoa/appkit_utils.h index 14f6c55070e..a3b46d13329 100644 --- a/chromium/ui/base/cocoa/appkit_utils.h +++ b/chromium/ui/base/cocoa/appkit_utils.h @@ -7,15 +7,15 @@ #import -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { // Whether a force-click event on the touchpad should invoke Quick Look. -UI_BASE_EXPORT bool ForceClickInvokesQuickLook(); +COMPONENT_EXPORT(UI_BASE) bool ForceClickInvokesQuickLook(); // Returns true if both CGFloat values are equal. -UI_BASE_EXPORT bool IsCGFloatEqual(CGFloat a, CGFloat b); +COMPONENT_EXPORT(UI_BASE) bool IsCGFloatEqual(CGFloat a, CGFloat b); } // namespace ui diff --git a/chromium/ui/base/cocoa/base_view.h b/chromium/ui/base/cocoa/base_view.h index d9194c2f629..989196e8e19 100644 --- a/chromium/ui/base/cocoa/base_view.h +++ b/chromium/ui/base/cocoa/base_view.h @@ -7,16 +7,16 @@ #import +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" #import "ui/base/cocoa/tracking_area.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/geometry/rect.h" // A view that provides common functionality that many views will need: // - Automatic registration for mouse-moved events. // - Funneling of mouse and key events to two methods // - Coordinate conversion utilities -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface BaseView : NSView { @public enum EventHandled { @@ -57,7 +57,7 @@ UI_BASE_EXPORT // The name is |kViewDidBecomeFirstResponder|, the object is the view, and the // NSSelectionDirection is wrapped in an NSNumber under the key // |kSelectionDirection|. -UI_BASE_EXPORT extern NSString* kViewDidBecomeFirstResponder; -UI_BASE_EXPORT extern NSString* kSelectionDirection; +COMPONENT_EXPORT(UI_BASE) extern NSString* kViewDidBecomeFirstResponder; +COMPONENT_EXPORT(UI_BASE) extern NSString* kSelectionDirection; #endif // UI_BASE_COCOA_BASE_VIEW_H_ diff --git a/chromium/ui/base/cocoa/base_view.mm b/chromium/ui/base/cocoa/base_view.mm index 55ecf52defd..05ac7edca8b 100644 --- a/chromium/ui/base/cocoa/base_view.mm +++ b/chromium/ui/base/cocoa/base_view.mm @@ -4,6 +4,7 @@ #include "ui/base/cocoa/base_view.h" +#include "base/check_op.h" #include "base/mac/mac_util.h" NSString* kViewDidBecomeFirstResponder = diff --git a/chromium/ui/base/cocoa/bubble_closer.h b/chromium/ui/base/cocoa/bubble_closer.h index 39a2f450d5a..806d7352726 100644 --- a/chromium/ui/base/cocoa/bubble_closer.h +++ b/chromium/ui/base/cocoa/bubble_closer.h @@ -8,9 +8,9 @@ #include #include "base/callback.h" +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/cocoa/weak_ptr_nsobject.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/native_widget_types.h" namespace ui { @@ -18,7 +18,7 @@ namespace ui { // Monitors mouse events to allow a regular window to have menu-like popup // behavior when clicking outside the window. This is needed because macOS // suppresses window activation events when clicking rapidly. -class UI_BASE_EXPORT BubbleCloser { +class COMPONENT_EXPORT(UI_BASE) BubbleCloser { public: // Installs an event monitor watching for mouse clicks outside of |window| or // any of its child windows. Invokes |on_click_outside| on each event. diff --git a/chromium/ui/base/cocoa/cocoa_base_utils.h b/chromium/ui/base/cocoa/cocoa_base_utils.h index 627fe3ba325..05c7526f8d4 100644 --- a/chromium/ui/base/cocoa/cocoa_base_utils.h +++ b/chromium/ui/base/cocoa/cocoa_base_utils.h @@ -7,7 +7,7 @@ #import -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #include "ui/base/window_open_disposition.h" namespace ui { @@ -15,24 +15,26 @@ namespace ui { // Retrieves the WindowOpenDisposition used to open a link from a user gesture // represented by |event|. For example, a Cmd+Click would mean open the // associated link in a background tab. -UI_BASE_EXPORT WindowOpenDisposition - WindowOpenDispositionFromNSEvent(NSEvent* event); +COMPONENT_EXPORT(UI_BASE) +WindowOpenDisposition WindowOpenDispositionFromNSEvent(NSEvent* event); // Retrieves the WindowOpenDisposition used to open a link from a user gesture // represented by |event|, but instead use the modifier flags given by |flags|, // which is the same format as |-NSEvent modifierFlags|. This allows // substitution of the modifiers without having to create a new event from // scratch. -UI_BASE_EXPORT WindowOpenDisposition - WindowOpenDispositionFromNSEventWithFlags(NSEvent* event, NSUInteger flags); +COMPONENT_EXPORT(UI_BASE) +WindowOpenDisposition WindowOpenDispositionFromNSEventWithFlags( + NSEvent* event, + NSUInteger flags); // Converts a point from window coordinates to screen coordinates. -UI_BASE_EXPORT NSPoint ConvertPointFromWindowToScreen(NSWindow* window, - NSPoint point); +COMPONENT_EXPORT(UI_BASE) +NSPoint ConvertPointFromWindowToScreen(NSWindow* window, NSPoint point); // Converts a point from screen coordinates to window coordinates. -UI_BASE_EXPORT NSPoint ConvertPointFromScreenToWindow(NSWindow* window, - NSPoint point); +COMPONENT_EXPORT(UI_BASE) +NSPoint ConvertPointFromScreenToWindow(NSWindow* window, NSPoint point); } // namespace ui diff --git a/chromium/ui/base/cocoa/command_dispatcher.h b/chromium/ui/base/cocoa/command_dispatcher.h index 0fca8887e6a..1203c0a4df2 100644 --- a/chromium/ui/base/cocoa/command_dispatcher.h +++ b/chromium/ui/base/cocoa/command_dispatcher.h @@ -7,8 +7,8 @@ #import +#include "base/component_export.h" #import "base/mac/scoped_nsobject.h" -#include "ui/base/ui_base_export.h" @protocol CommandDispatcherDelegate; @protocol CommandDispatchingWindow; @@ -21,7 +21,7 @@ // NSWindow can use CommandDispatcher by implementing CommandDispatchingWindow // and overriding -[NSWindow performKeyEquivalent:] and -[NSWindow sendEvent:] // to call the respective CommandDispatcher methods. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface CommandDispatcher : NSObject @property(assign, nonatomic) id delegate; diff --git a/chromium/ui/base/cocoa/command_dispatcher.mm b/chromium/ui/base/cocoa/command_dispatcher.mm index efe7a1862ce..1ae7b1707a7 100644 --- a/chromium/ui/base/cocoa/command_dispatcher.mm +++ b/chromium/ui/base/cocoa/command_dispatcher.mm @@ -23,6 +23,44 @@ - (NSWindow*)bubbleParent; @end +namespace { + +// Duplicate the given key event, but changing the associated window. +NSEvent* KeyEventForWindow(NSWindow* window, NSEvent* event) { + NSEventType event_type = [event type]; + + // Convert the event's location from the original window's coordinates into + // our own. + NSPoint location = [event locationInWindow]; + location = ui::ConvertPointFromWindowToScreen([event window], location); + location = ui::ConvertPointFromScreenToWindow(window, location); + + // Various things *only* apply to key down/up. + bool is_a_repeat = false; + NSString* characters = nil; + NSString* charactors_ignoring_modifiers = nil; + if (event_type == NSKeyDown || event_type == NSKeyUp) { + is_a_repeat = [event isARepeat]; + characters = [event characters]; + charactors_ignoring_modifiers = [event charactersIgnoringModifiers]; + } + + // This synthesis may be slightly imperfect: we provide nil for the context, + // since I (viettrungluu) am sceptical that putting in the original context + // (if one is given) is valid. + return [NSEvent keyEventWithType:event_type + location:location + modifierFlags:[event modifierFlags] + timestamp:[event timestamp] + windowNumber:[window windowNumber] + context:nil + characters:characters + charactersIgnoringModifiers:charactors_ignoring_modifiers + isARepeat:is_a_repeat + keyCode:[event keyCode]]; +} + +} // namespace @implementation CommandDispatcher { @private @@ -169,10 +207,13 @@ return YES; // Pretend it's been handled in an effort to limit damage. } - // TODO(lgrey): This is a temporary sanity check since the code that was - // here previously did *not* assume this. Remove shortly after this lands if - // nothing blew up. - DCHECK_EQ([event window], _owner); + // Sometimes, an event will be redispatched from a child window to a parent + // window to allow the parent window a chance to handle it. In that case, fix + // up the native event to reference the correct window. Failure to do this can + // cause infinite redispatch loops; see https://crbug.com/1085578 for more + // details. + if ([event window] != _owner) + event = KeyEventForWindow(_owner, event); // Redispatch the event. _eventHandled = YES; diff --git a/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.h b/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.h index 2bc672c9840..8942102b232 100644 --- a/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.h +++ b/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.h @@ -7,11 +7,11 @@ #import +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" -#include "ui/base/ui_base_export.h" // Base class for all constrained window animation classes. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface ConstrainedWindowAnimationBase : NSAnimation { @protected base::scoped_nsobject _window; @@ -22,17 +22,17 @@ UI_BASE_EXPORT @end // An animation to show a window. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface ConstrainedWindowAnimationShow : ConstrainedWindowAnimationBase @end // An animation to hide a window. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface ConstrainedWindowAnimationHide : ConstrainedWindowAnimationBase @end // An animation that pulses the window by growing it then shrinking it back. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface ConstrainedWindowAnimationPulse : ConstrainedWindowAnimationBase @end diff --git a/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm b/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm index ce16e17dfcb..c8ce99f708b 100644 --- a/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm +++ b/chromium/ui/base/cocoa/constrained_window/constrained_window_animation.mm @@ -11,6 +11,7 @@ #include "base/location.h" #import "base/mac/foundation_util.h" #include "base/native_library.h" +#include "base/notreached.h" #include "base/stl_util.h" #include "ui/gfx/animation/tween.h" diff --git a/chromium/ui/base/cocoa/controls/button_utils.h b/chromium/ui/base/cocoa/controls/button_utils.h index 740c914140a..d9b039f0fa9 100644 --- a/chromium/ui/base/cocoa/controls/button_utils.h +++ b/chromium/ui/base/cocoa/controls/button_utils.h @@ -5,11 +5,11 @@ #ifndef UI_BASE_COCOA_CONTROLS_BUTTON_UTILS_H_ #define UI_BASE_COCOA_CONTROLS_BUTTON_UTILS_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #include -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface ButtonUtils : NSObject // These methods are a polyfill for convenience constructors that exist on diff --git a/chromium/ui/base/cocoa/controls/textfield_utils.h b/chromium/ui/base/cocoa/controls/textfield_utils.h index dea04b87f0e..4fd54c6c0ea 100644 --- a/chromium/ui/base/cocoa/controls/textfield_utils.h +++ b/chromium/ui/base/cocoa/controls/textfield_utils.h @@ -5,11 +5,11 @@ #ifndef UI_BASE_COCOA_CONTROLS_TEXTFIELD_UTILS_H_ #define UI_BASE_COCOA_CONTROLS_TEXTFIELD_UTILS_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #include -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface TextFieldUtils : NSObject // This method is a polyfill for a method on NSTextField on macOS 10.12+. diff --git a/chromium/ui/base/cocoa/defaults_utils.h b/chromium/ui/base/cocoa/defaults_utils.h index ff68374f8a0..7845045d5c4 100644 --- a/chromium/ui/base/cocoa/defaults_utils.h +++ b/chromium/ui/base/cocoa/defaults_utils.h @@ -5,15 +5,15 @@ #ifndef UI_BASE_COCOA_DEFAULTS_UTILS_H_ #define UI_BASE_COCOA_DEFAULTS_UTILS_H_ +#include "base/component_export.h" #include "base/time/time.h" -#include "ui/base/ui_base_export.h" namespace ui { // Returns the text insertion caret blink period, if one is configured in // NSUserDefaults. -UI_BASE_EXPORT bool TextInsertionCaretBlinkPeriod(base::TimeDelta* period); - +COMPONENT_EXPORT(UI_BASE) +bool TextInsertionCaretBlinkPeriod(base::TimeDelta* period); } #endif diff --git a/chromium/ui/base/cocoa/find_pasteboard.h b/chromium/ui/base/cocoa/find_pasteboard.h index 4cda454dbc2..3dc0867ca8e 100644 --- a/chromium/ui/base/cocoa/find_pasteboard.h +++ b/chromium/ui/base/cocoa/find_pasteboard.h @@ -11,10 +11,10 @@ #import +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" -#include "ui/base/ui_base_export.h" -UI_BASE_EXPORT extern NSString* kFindPasteboardChangedNotification; +COMPONENT_EXPORT(UI_BASE) extern NSString* kFindPasteboardChangedNotification; // Manages the find pasteboard. Use this to copy text to the find pasteboard, // to get the text currently on the find pasteboard, and to receive @@ -25,7 +25,7 @@ UI_BASE_EXPORT extern NSString* kFindPasteboardChangedNotification; // This is not thread-safe and must be used on the main thread. // // This is supposed to be a singleton. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface FindPasteboard : NSObject { @private base::scoped_nsobject _findText; @@ -54,6 +54,6 @@ UI_BASE_EXPORT #endif // __OBJC__ // Also provide a c++ interface -UI_BASE_EXPORT base::string16 GetFindPboardText(); +COMPONENT_EXPORT(UI_BASE) base::string16 GetFindPboardText(); #endif // UI_BASE_COCOA_FIND_PASTEBOARD_H_ diff --git a/chromium/ui/base/cocoa/flipped_view.h b/chromium/ui/base/cocoa/flipped_view.h index 7bc117779d8..c5dce1a553d 100644 --- a/chromium/ui/base/cocoa/flipped_view.h +++ b/chromium/ui/base/cocoa/flipped_view.h @@ -7,13 +7,13 @@ #import -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" // A view where the Y axis is flipped such that the origin is at the top left // and Y value increases downwards. Drawing is flipped so that layout of the // sections is easier. Apple recommends flipping the coordinate origin when // doing a lot of text layout because it's more natural. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface FlippedView : NSView @end diff --git a/chromium/ui/base/cocoa/focus_tracker.h b/chromium/ui/base/cocoa/focus_tracker.h index f77559ea098..a676e08ef15 100644 --- a/chromium/ui/base/cocoa/focus_tracker.h +++ b/chromium/ui/base/cocoa/focus_tracker.h @@ -4,15 +4,15 @@ #import +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" -#include "ui/base/ui_base_export.h" // A class that handles saving and restoring focus. An instance of // this class snapshots the currently focused view when it is // constructed, and callers can use restoreFocus to return focus to // that view. FocusTracker will not restore focus to views that are // no longer in the view hierarchy or are not in the correct window. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface FocusTracker : NSObject { @private base::scoped_nsobject _focusedView; diff --git a/chromium/ui/base/cocoa/focus_window_set.h b/chromium/ui/base/cocoa/focus_window_set.h index e4b6d9f0471..820195f6978 100644 --- a/chromium/ui/base/cocoa/focus_window_set.h +++ b/chromium/ui/base/cocoa/focus_window_set.h @@ -7,7 +7,7 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #include "ui/gfx/native_widget_types.h" namespace ui { @@ -15,7 +15,8 @@ namespace ui { // Brings a group of windows to the front without changing their order, and // makes the frontmost one key and main. If none are visible, the frontmost // miniaturized window is deminiaturized. -UI_BASE_EXPORT void FocusWindowSet(const std::set& windows); +COMPONENT_EXPORT(UI_BASE) +void FocusWindowSet(const std::set& windows); // Brings a group of windows to the front without changing their // order, and makes the frontmost one key and main. If none are @@ -24,8 +25,8 @@ UI_BASE_EXPORT void FocusWindowSet(const std::set& windows); // behavior. Unlike FocusWindowSet, only windows on the current space // are considered. It also ignores the hidden state of windows; the // window system may be in the middle of unhiding the application. -UI_BASE_EXPORT void FocusWindowSetOnCurrentSpace( - const std::set& windows); +COMPONENT_EXPORT(UI_BASE) +void FocusWindowSetOnCurrentSpace(const std::set& windows); } // namespace ui diff --git a/chromium/ui/base/cocoa/focus_window_set.mm b/chromium/ui/base/cocoa/focus_window_set.mm index 498df6e2951..06e7223ded8 100644 --- a/chromium/ui/base/cocoa/focus_window_set.mm +++ b/chromium/ui/base/cocoa/focus_window_set.mm @@ -4,6 +4,7 @@ #import +#include "base/check.h" #include "ui/base/cocoa/focus_window_set.h" namespace ui { diff --git a/chromium/ui/base/cocoa/menu_controller.h b/chromium/ui/base/cocoa/menu_controller.h index d6dd4f0ced2..8dc3cdb50a5 100644 --- a/chromium/ui/base/cocoa/menu_controller.h +++ b/chromium/ui/base/cocoa/menu_controller.h @@ -7,9 +7,9 @@ #import +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace ui { class MenuModel; @@ -21,7 +21,7 @@ class MenuModel; // allow for hierarchical menus). The tag is the index into that model for // that particular item. It is important that the model outlives this object // as it only maintains weak references. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface MenuControllerCocoa : NSObject diff --git a/chromium/ui/base/cocoa/permissions_utils.h b/chromium/ui/base/cocoa/permissions_utils.h index 14355053988..a8ec034cdf2 100644 --- a/chromium/ui/base/cocoa/permissions_utils.h +++ b/chromium/ui/base/cocoa/permissions_utils.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_COCOA_PERMISSIONS_UTILS_H_ #define UI_BASE_COCOA_PERMISSIONS_UTILS_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -14,7 +14,7 @@ namespace ui { // requires a permission authorization. There is no direct way to query the // permission state, so this uses a heuristic to evaluate whether the permission // has been granted. -UI_BASE_EXPORT bool IsScreenCaptureAllowed(); +COMPONENT_EXPORT(UI_BASE) bool IsScreenCaptureAllowed(); } // namespace ui diff --git a/chromium/ui/base/cocoa/quartz_util.h b/chromium/ui/base/cocoa/quartz_util.h index dd3201fe925..bba1f2016e5 100644 --- a/chromium/ui/base/cocoa/quartz_util.h +++ b/chromium/ui/base/cocoa/quartz_util.h @@ -5,15 +5,15 @@ #ifndef UI_BASE_COCOA_QUARTZ_UTIL_H_ #define UI_BASE_COCOA_QUARTZ_UTIL_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { // Calls +[CATransaction begin]. -UI_BASE_EXPORT void BeginCATransaction(); +COMPONENT_EXPORT(UI_BASE) void BeginCATransaction(); // Calls +[CATransaction commit]. -UI_BASE_EXPORT void CommitCATransaction(); +COMPONENT_EXPORT(UI_BASE) void CommitCATransaction(); } // namespace ui diff --git a/chromium/ui/base/cocoa/remote_accessibility_api.h b/chromium/ui/base/cocoa/remote_accessibility_api.h index 2a58aebabb2..e7adfee3210 100644 --- a/chromium/ui/base/cocoa/remote_accessibility_api.h +++ b/chromium/ui/base/cocoa/remote_accessibility_api.h @@ -8,8 +8,8 @@ #import #include +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" -#include "ui/base/ui_base_export.h" @interface NSAccessibilityRemoteUIElement : NSObject + (void)registerRemoteUIProcessIdentifier:(int)pid; @@ -23,7 +23,7 @@ namespace ui { // Helper functions to implement the above functions using std::vectors intsead // of NSData. -class UI_BASE_EXPORT RemoteAccessibility { +class COMPONENT_EXPORT(UI_BASE) RemoteAccessibility { public: static std::vector GetTokenForLocalElement(id element); static base::scoped_nsobject diff --git a/chromium/ui/base/cocoa/remote_layer_api.h b/chromium/ui/base/cocoa/remote_layer_api.h index 2057fe69d1b..d684614589c 100644 --- a/chromium/ui/base/cocoa/remote_layer_api.h +++ b/chromium/ui/base/cocoa/remote_layer_api.h @@ -11,7 +11,7 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" // The CGSConnectionID is used to create the CAContext in the process that is // going to share the CALayers that it is rendering to another process to @@ -54,7 +54,7 @@ namespace ui { // This function will check if all of the interfaces listed above are supported // on the system, and return true if they are. -bool UI_BASE_EXPORT RemoteLayerAPISupported(); +bool COMPONENT_EXPORT(UI_BASE) RemoteLayerAPISupported(); } // namespace ui diff --git a/chromium/ui/base/cocoa/secure_password_input.h b/chromium/ui/base/cocoa/secure_password_input.h index ca90d3964a5..d272cd1bd6a 100644 --- a/chromium/ui/base/cocoa/secure_password_input.h +++ b/chromium/ui/base/cocoa/secure_password_input.h @@ -5,13 +5,13 @@ #ifndef UI_BASE_COCOA_SECURE_PASSWORD_INPUT_H_ #define UI_BASE_COCOA_SECURE_PASSWORD_INPUT_H_ +#include "base/component_export.h" #include "base/macros.h" -#include "ui/base/ui_base_export.h" namespace ui { // Enables the secure password input mode while in scope. -class UI_BASE_EXPORT ScopedPasswordInputEnabler { +class COMPONENT_EXPORT(UI_BASE) ScopedPasswordInputEnabler { public: ScopedPasswordInputEnabler(); ~ScopedPasswordInputEnabler(); diff --git a/chromium/ui/base/cocoa/text_services_context_menu.cc b/chromium/ui/base/cocoa/text_services_context_menu.cc index d149dd8df63..0dcfe6db2b4 100644 --- a/chromium/ui/base/cocoa/text_services_context_menu.cc +++ b/chromium/ui/base/cocoa/text_services_context_menu.cc @@ -17,22 +17,6 @@ namespace { -enum MenuCommands { - // These must not overlap with the command IDs used by other menus that - // incorporate text services. - // TODO(ellyjones): This is an ugly global dependency, especially on - // //ui/views. What can we do about this? Can we get rid of the global - // implicit namespace of command IDs? - kSpeechMenu = 100, - kSpeechStartSpeaking, - kSpeechStopSpeaking, - - kWritingDirectionMenu, - kWritingDirectionDefault, - kWritingDirectionLtr, - kWritingDirectionRtl, -}; - // The speech channel used for speaking. This is shared to check if a speech // channel is currently speaking. SpeechChannel g_speech_channel; @@ -41,11 +25,11 @@ SpeechChannel g_speech_channel; // |command_id|. base::i18n::TextDirection GetTextDirectionFromCommandId(int command_id) { switch (command_id) { - case kWritingDirectionDefault: + case ui::TextServicesContextMenu::kWritingDirectionDefault: return base::i18n::UNKNOWN_DIRECTION; - case kWritingDirectionLtr: + case ui::TextServicesContextMenu::kWritingDirectionLtr: return base::i18n::LEFT_TO_RIGHT; - case kWritingDirectionRtl: + case ui::TextServicesContextMenu::kWritingDirectionRtl: return base::i18n::RIGHT_TO_LEFT; default: NOTREACHED(); diff --git a/chromium/ui/base/cocoa/text_services_context_menu.h b/chromium/ui/base/cocoa/text_services_context_menu.h index e9d48efa68c..a32b76f9523 100644 --- a/chromium/ui/base/cocoa/text_services_context_menu.h +++ b/chromium/ui/base/cocoa/text_services_context_menu.h @@ -5,20 +5,36 @@ #ifndef UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_ #define UI_BASE_COCOA_TEXT_SERVICES_CONTEXT_MENU_H_ +#include "base/component_export.h" #include "base/i18n/rtl.h" #include "base/macros.h" #include "base/strings/string16.h" #include "ui/base/models/simple_menu_model.h" -#include "ui/base/ui_base_export.h" namespace ui { // This class is used to append and handle the Speech and BiDi submenu for the // context menu. -class UI_BASE_EXPORT TextServicesContextMenu +class COMPONENT_EXPORT(UI_BASE) TextServicesContextMenu : public SimpleMenuModel::Delegate { public: - class UI_BASE_EXPORT Delegate { + enum MenuCommands { + // These must not overlap with the command IDs used by other menus that + // incorporate text services. + // TODO(ellyjones): This is an ugly global dependency, especially on + // //ui/views. What can we do about this? Can we get rid of the global + // implicit namespace of command IDs? + kSpeechMenu = 100, + kSpeechStartSpeaking, + kSpeechStopSpeaking, + + kWritingDirectionMenu, + kWritingDirectionDefault, + kWritingDirectionLtr, + kWritingDirectionRtl, + }; + + class COMPONENT_EXPORT(UI_BASE) Delegate { public: // Returns the selected text. virtual base::string16 GetSelectedText() const = 0; diff --git a/chromium/ui/base/cocoa/tool_tip_base_view.h b/chromium/ui/base/cocoa/tool_tip_base_view.h index 086530a4894..32d354fd525 100644 --- a/chromium/ui/base/cocoa/tool_tip_base_view.h +++ b/chromium/ui/base/cocoa/tool_tip_base_view.h @@ -7,12 +7,13 @@ #import +#include "base/component_export.h" #import "ui/base/cocoa/base_view.h" // An NSiew that allows tooltip text to be set at the current mouse location. It // can take effect immediately, but won't appear unless the tooltip delay has // elapsed. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface ToolTipBaseView : BaseView { @private // These are part of the magic tooltip code from WebKit's WebHTMLView: diff --git a/chromium/ui/base/cocoa/touch_bar_util.h b/chromium/ui/base/cocoa/touch_bar_util.h index 457099bd9a5..f69d2a392f1 100644 --- a/chromium/ui/base/cocoa/touch_bar_util.h +++ b/chromium/ui/base/cocoa/touch_bar_util.h @@ -8,7 +8,7 @@ #import #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -29,30 +29,29 @@ enum TouchBarAction { }; // Logs the sample's UMA metrics into the DefaultTouchBar.Metrics histogram. -UI_BASE_EXPORT void LogTouchBarUMA(TouchBarAction command); +COMPONENT_EXPORT(UI_BASE) void LogTouchBarUMA(TouchBarAction command); // Returns the NSTouchBar Class. -UI_BASE_EXPORT Class NSTouchBar(); +COMPONENT_EXPORT(UI_BASE) Class NSTouchBar(); // Returns the NSCustomTouchBarItem Class. -UI_BASE_EXPORT Class NSCustomTouchBarItem(); +COMPONENT_EXPORT(UI_BASE) Class NSCustomTouchBarItem(); // Returns the NSGroupTouchBarItem Class. -UI_BASE_EXPORT Class NSGroupTouchBarItem(); +COMPONENT_EXPORT(UI_BASE) Class NSGroupTouchBarItem(); // Returns a stylized blue button for the touch bar. The button performs // |action| from the |target|. API_AVAILABLE(macosx(10.12.2)) -UI_BASE_EXPORT NSButton* GetBlueTouchBarButton(NSString* title, - id target, - SEL action); +COMPONENT_EXPORT(UI_BASE) +NSButton* GetBlueTouchBarButton(NSString* title, id target, SEL action); // Creates a touch bar identifier with the given |id|. -UI_BASE_EXPORT NSString* GetTouchBarId(NSString* touch_bar_id); +COMPONENT_EXPORT(UI_BASE) NSString* GetTouchBarId(NSString* touch_bar_id); // Creates a touch Bar jtem identifier. -UI_BASE_EXPORT NSString* GetTouchBarItemId(NSString* touch_bar_id, - NSString* item_id); +COMPONENT_EXPORT(UI_BASE) +NSString* GetTouchBarItemId(NSString* touch_bar_id, NSString* item_id); } // namespace ui diff --git a/chromium/ui/base/cocoa/tracking_area.h b/chromium/ui/base/cocoa/tracking_area.h index 4d7cd334e72..9d4c1c42783 100644 --- a/chromium/ui/base/cocoa/tracking_area.h +++ b/chromium/ui/base/cocoa/tracking_area.h @@ -7,15 +7,15 @@ #import +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" #include "base/macros.h" -#include "ui/base/ui_base_export.h" @class CrTrackingAreaOwnerProxy; // The CrTrackingArea can be used in place of an NSTrackingArea to shut off // messaging to the |owner| at a specific point in time. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface CrTrackingArea : NSTrackingArea { @private base::scoped_nsobject _ownerProxy; @@ -39,7 +39,7 @@ namespace ui { // Use an instance of this class to call |-clearOwner| on the |tracking_area_| // when this goes out of scope. -class UI_BASE_EXPORT ScopedCrTrackingArea { +class COMPONENT_EXPORT(UI_BASE) ScopedCrTrackingArea { public: // Takes ownership of |tracking_area| without retaining it. explicit ScopedCrTrackingArea(CrTrackingArea* tracking_area = nil); diff --git a/chromium/ui/base/cocoa/underlay_opengl_hosting_window.h b/chromium/ui/base/cocoa/underlay_opengl_hosting_window.h index d673c31a0f3..ec1c6c972ee 100644 --- a/chromium/ui/base/cocoa/underlay_opengl_hosting_window.h +++ b/chromium/ui/base/cocoa/underlay_opengl_hosting_window.h @@ -7,12 +7,12 @@ #import -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" // Common base class for windows that host a OpenGL surface that renders under // the window. Previously contained methods related to hole punching, now just // contains common asserts. -UI_BASE_EXPORT +COMPONENT_EXPORT(UI_BASE) @interface UnderlayOpenGLHostingWindow : NSWindow @end diff --git a/chromium/ui/base/cocoa/views_hostable.h b/chromium/ui/base/cocoa/views_hostable.h index 46f0277491f..9a9ae9324a5 100644 --- a/chromium/ui/base/cocoa/views_hostable.h +++ b/chromium/ui/base/cocoa/views_hostable.h @@ -7,7 +7,7 @@ #import -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/native_widget_types.h" diff --git a/chromium/ui/base/cocoa/weak_ptr_nsobject.h b/chromium/ui/base/cocoa/weak_ptr_nsobject.h index fa9580e94ec..6d50aa00b9e 100644 --- a/chromium/ui/base/cocoa/weak_ptr_nsobject.h +++ b/chromium/ui/base/cocoa/weak_ptr_nsobject.h @@ -5,8 +5,8 @@ #ifndef UI_BASE_COCOA_WEAK_PTR_NSOBJECT_H_ #define UI_BASE_COCOA_WEAK_PTR_NSOBJECT_H_ +#include "base/component_export.h" #include "base/macros.h" -#include "ui/base/ui_base_export.h" #if defined(__OBJC__) @class WeakPtrNSObject; @@ -20,7 +20,7 @@ namespace internal { // Non-templatized base for WeakPtrNSObjectFactory with utility functions. This // mainly serves to hide the objective-C code from the header, so it can be // included in cc files. -class UI_BASE_EXPORT WeakPtrNSObjectFactoryBase { +class COMPONENT_EXPORT(UI_BASE) WeakPtrNSObjectFactoryBase { protected: static WeakPtrNSObject* Create(void* owner); static void* UnWrap(WeakPtrNSObject* handle); diff --git a/chromium/ui/base/cocoa/window_size_constants.h b/chromium/ui/base/cocoa/window_size_constants.h index bb94018fd53..0f096c95629 100644 --- a/chromium/ui/base/cocoa/window_size_constants.h +++ b/chromium/ui/base/cocoa/window_size_constants.h @@ -5,14 +5,14 @@ #ifndef UI_BASE_COCOA_WINDOW_SIZE_CONSTANTS_H_ #define UI_BASE_COCOA_WINDOW_SIZE_CONSTANTS_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #import namespace ui { // It is not valid to make a zero-sized window. Use this constant instead. -UI_BASE_EXPORT extern const NSRect kWindowSizeDeterminedLater; +COMPONENT_EXPORT(UI_BASE) extern const NSRect kWindowSizeDeterminedLater; } // namespace ui diff --git a/chromium/ui/base/cursor/BUILD.gn b/chromium/ui/base/cursor/BUILD.gn index e69e571c44b..f16386ecf4a 100644 --- a/chromium/ui/base/cursor/BUILD.gn +++ b/chromium/ui/base/cursor/BUILD.gn @@ -4,39 +4,123 @@ import("//build/config/ui.gni") -component("cursor") { - output_name = "ui_base_cursor" - +# This component was split from :cursor to allow Blink to depend on it without +# bringing all of //ui/base/cursor. +component("cursor_base") { + output_name = "ui_base_cursor_base" sources = [ "cursor.cc", "cursor.h", + "cursor_factory.cc", + "cursor_factory.h", "cursor_size.h", ] - - defines = [ "IS_UI_BASE_CURSOR_IMPL" ] - + defines = [ "IS_UI_BASE_CURSOR_BASE_IMPL" ] public_deps = [ "//base", "//skia", "//ui/base/cursor/mojom:cursor_type", "//ui/gfx/geometry", ] - deps = [ "//ui/gfx:geometry_skia" ] - if (use_x11 && use_aura) { - sources += [ "cursor_x11.cc" ] - - deps += [ "//ui/base/x" ] + if (is_win) { + sources += [ "cursor_win.cc" ] } - if (use_ozone) { + if (use_x11 || use_ozone) { sources += [ "cursor_ozone.cc" ] + } +} + +source_set("theme_manager") { + sources = [ + "cursor_theme_manager.cc", + "cursor_theme_manager.h", + "cursor_theme_manager_observer.h", + ] + deps = [ "//base" ] +} - deps += [ "//ui/ozone:ozone_base" ] +if (use_aura) { + component("cursor") { + output_name = "ui_base_cursor" + sources = [ + "cursor_loader.h", + "cursor_lookup.cc", + "cursor_lookup.h", + "cursor_util.cc", + "cursor_util.h", + "cursors_aura.cc", + "cursors_aura.h", + "image_cursors.cc", + "image_cursors.h", + ] + defines = [ "IS_UI_BASE_CURSOR_IMPL" ] + public_deps = [ + ":cursor_base", + "//base", + "//ui/base/cursor/mojom:cursor_type", + "//ui/display", + "//ui/gfx:native_widget_types", + ] + deps = [ + "//skia", + "//ui/base", + "//ui/gfx", + "//ui/gfx:geometry_skia", + "//ui/gfx/geometry", + "//ui/resources:ui_resources_grd", + ] + + if (is_win) { + sources += [ + "cursor_loader_win.cc", + "cursor_loader_win.h", + ] + deps += [ "//ui/resources:ui_unscaled_resources_grd" ] + } + + if (use_ozone) { + sources += [ + "ozone/bitmap_cursor_factory_ozone.cc", + "ozone/bitmap_cursor_factory_ozone.h", + ] + public_deps += [ + "//skia", + "//ui/gfx/geometry", + ] + } + + if (use_x11 || use_ozone) { + sources += [ + "cursor_loader_ozone.cc", + "cursor_loader_ozone.h", + ] + } } +} - if (is_win) { - sources += [ "cursor_win.cc" ] +source_set("unittests") { + testonly = true + sources = [] + deps = [ + "//skia", + "//testing/gtest", + "//ui/gfx/geometry", + ] + + if (!is_ios) { + sources += [ "cursor_unittest.cc" ] + deps += [ + ":cursor_base", + "//ui/base/cursor/mojom:cursor_type", + "//ui/gfx:geometry_skia", + ] + } + + if (use_aura) { + sources += [ "cursor_util_unittest.cc" ] + deps += [ ":cursor" ] } } diff --git a/chromium/ui/base/cursor/DEPS b/chromium/ui/base/cursor/DEPS deleted file mode 100644 index de08167e272..00000000000 --- a/chromium/ui/base/cursor/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+ui/ozone/public", -] diff --git a/chromium/ui/base/cursor/cursor.h b/chromium/ui/base/cursor/cursor.h index 095798ce964..835027a9ac4 100644 --- a/chromium/ui/base/cursor/cursor.h +++ b/chromium/ui/base/cursor/cursor.h @@ -21,14 +21,12 @@ namespace ui { #if defined(OS_WIN) typedef ::HCURSOR PlatformCursor; -#elif defined(USE_X11) -typedef unsigned long PlatformCursor; #else typedef void* PlatformCursor; #endif // Ref-counted cursor that supports both default and custom cursors. -class COMPONENT_EXPORT(UI_BASE_CURSOR) Cursor { +class COMPONENT_EXPORT(UI_BASE_CURSOR_BASE) Cursor { public: Cursor(); diff --git a/chromium/ui/base/cursor/cursor_factory.cc b/chromium/ui/base/cursor/cursor_factory.cc new file mode 100644 index 00000000000..43645a5d446 --- /dev/null +++ b/chromium/ui/base/cursor/cursor_factory.cc @@ -0,0 +1,68 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/cursor/cursor_factory.h" + +#include + +#include "base/check.h" +#include "base/check_op.h" +#include "base/notreached.h" + +namespace ui { + +namespace { + +CursorFactory* g_instance = nullptr; + +} // namespace + +CursorFactory::CursorFactory() { + DCHECK(!g_instance) << "There should only be a single CursorFactory."; + g_instance = this; +} + +CursorFactory::~CursorFactory() { + DCHECK_EQ(g_instance, this); + g_instance = nullptr; +} + +CursorFactory* CursorFactory::GetInstance() { + DCHECK(g_instance); + return g_instance; +} + +base::Optional CursorFactory::GetDefaultCursor( + mojom::CursorType type) { + NOTIMPLEMENTED(); + return base::nullopt; +} + +PlatformCursor CursorFactory::CreateImageCursor(const SkBitmap& bitmap, + const gfx::Point& hotspot) { + NOTIMPLEMENTED(); + return 0; +} + +PlatformCursor CursorFactory::CreateAnimatedCursor( + const std::vector& bitmaps, + const gfx::Point& hotspot, + int frame_delay_ms) { + NOTIMPLEMENTED(); + return 0; +} + +void CursorFactory::RefImageCursor(PlatformCursor cursor) { + NOTIMPLEMENTED(); +} + +void CursorFactory::UnrefImageCursor(PlatformCursor cursor) { + NOTIMPLEMENTED(); +} + +void CursorFactory::ObserveThemeChanges() { + NOTIMPLEMENTED(); +} + +} // namespace ui diff --git a/chromium/ui/base/cursor/cursor_factory.h b/chromium/ui/base/cursor/cursor_factory.h new file mode 100644 index 00000000000..f038a422819 --- /dev/null +++ b/chromium/ui/base/cursor/cursor_factory.h @@ -0,0 +1,67 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_CURSOR_CURSOR_FACTORY_H_ +#define UI_BASE_CURSOR_CURSOR_FACTORY_H_ + +#include + +#include "base/component_export.h" +#include "base/optional.h" +#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" + +class SkBitmap; + +namespace gfx { +class Point; +} + +namespace ui { +using PlatformCursor = void*; + +class COMPONENT_EXPORT(UI_BASE_CURSOR_BASE) CursorFactory { + public: + CursorFactory(); + virtual ~CursorFactory(); + + // Returns the thread-local instance. + static CursorFactory* GetInstance(); + + // Return the default cursor of the specified type. The types are listed in + // ui/base/cursor/cursor.h. Default cursors are managed by the implementation + // and must live indefinitely; there's no way to know when to free them. + // nullptr may be a valid value for the hidden cursor. When a default cursor + // is not available, base::nullopt is returned. + virtual base::Optional GetDefaultCursor( + mojom::CursorType type); + + // Return a image cursor from the specified image & hotspot. Image cursors + // are referenced counted and have an initial refcount of 1. Therefore, each + // CreateImageCursor call must be matched with a call to UnrefImageCursor. + virtual PlatformCursor CreateImageCursor(const SkBitmap& bitmap, + const gfx::Point& hotspot); + + // Return a animated cursor from the specified image & hotspot. Animated + // cursors are referenced counted and have an initial refcount of 1. + // Therefore, each CreateAnimatedCursor call must be matched with a call to + // UnrefImageCursor. + virtual PlatformCursor CreateAnimatedCursor( + const std::vector& bitmaps, + const gfx::Point& hotspot, + int frame_delay_ms); + + // Increment platform image cursor refcount. + virtual void RefImageCursor(PlatformCursor cursor); + + // Decrement platform image cursor refcount. + virtual void UnrefImageCursor(PlatformCursor cursor); + + // Called after CursorThemeManager is initialized, to be able to track + // cursor theme and size changes. + virtual void ObserveThemeChanges(); +}; + +} // namespace ui + +#endif // UI_BASE_CURSOR_CURSOR_FACTORY_H_ diff --git a/chromium/ui/base/cursor/cursor_loader.h b/chromium/ui/base/cursor/cursor_loader.h index 95141089ffe..2553c54e488 100644 --- a/chromium/ui/base/cursor/cursor_loader.h +++ b/chromium/ui/base/cursor/cursor_loader.h @@ -5,18 +5,19 @@ #ifndef UI_BASE_CURSOR_CURSOR_LOADER_H_ #define UI_BASE_CURSOR_CURSOR_LOADER_H_ -#include "base/logging.h" +#include "base/component_export.h" #include "base/macros.h" -#include "base/strings/string16.h" #include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" -#include "ui/base/ui_base_export.h" #include "ui/display/display.h" -#include "ui/gfx/geometry/point.h" #include "ui/gfx/native_widget_types.h" +namespace gfx { +class Point; +} + namespace ui { -class UI_BASE_EXPORT CursorLoader { +class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoader { public: CursorLoader() : scale_(1.f), rotation_(display::Display::ROTATE_0) {} virtual ~CursorLoader() {} diff --git a/chromium/ui/base/cursor/cursor_loader_ozone.cc b/chromium/ui/base/cursor/cursor_loader_ozone.cc index 8668095578e..6df16b5f1e7 100644 --- a/chromium/ui/base/cursor/cursor_loader_ozone.cc +++ b/chromium/ui/base/cursor/cursor_loader_ozone.cc @@ -6,15 +6,16 @@ #include -#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/cursor_factory.h" +#include "ui/base/cursor/cursor_size.h" #include "ui/base/cursor/cursor_util.h" +#include "ui/base/cursor/cursors_aura.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" -#include "ui/ozone/public/cursor_factory_ozone.h" namespace ui { CursorLoaderOzone::CursorLoaderOzone() { - factory_ = CursorFactoryOzone::GetInstance(); + factory_ = CursorFactory::GetInstance(); } CursorLoaderOzone::~CursorLoaderOzone() { @@ -29,7 +30,7 @@ void CursorLoaderOzone::LoadImageCursor(mojom::CursorType id, GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap); - image_cursors_[id] = factory_->CreateImageCursor(bitmap, hotspot, scale()); + image_cursors_[id] = factory_->CreateImageCursor(bitmap, hotspot); } void CursorLoaderOzone::LoadAnimatedCursor(mojom::CursorType id, @@ -43,7 +44,7 @@ void CursorLoaderOzone::LoadAnimatedCursor(mojom::CursorType id, resource_id, scale(), rotation(), &hotspot, &bitmaps); image_cursors_[id] = - factory_->CreateAnimatedCursor(bitmaps, hotspot, frame_delay_ms, scale()); + factory_->CreateAnimatedCursor(bitmaps, hotspot, frame_delay_ms); } void CursorLoaderOzone::UnloadAll() { @@ -53,22 +54,48 @@ void CursorLoaderOzone::UnloadAll() { } void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { - mojom::CursorType native_type = cursor->type(); - PlatformCursor platform; - - if (image_cursors_.count(native_type)) { - // An image cursor is loaded for this type. - platform = image_cursors_[native_type]; - } else if (native_type == mojom::CursorType::kCustom) { - // The platform cursor was already set via WebCursor::GetPlatformCursor. - platform = cursor->platform(); - } else { - // Use default cursor of this type. - platform = factory_->GetDefaultCursor(native_type); - } + DCHECK(cursor); + // The platform cursor was already set via WebCursor::GetPlatformCursor. + if (cursor->type() == mojom::CursorType::kCustom) + return; cursor->set_image_scale_factor(scale()); - cursor->SetPlatformCursor(platform); + cursor->SetPlatformCursor(CursorFromType(cursor->type())); +} + +PlatformCursor CursorLoaderOzone::CursorFromType(mojom::CursorType type) { + // An image cursor is loaded for this type. + if (image_cursors_.count(type)) + return image_cursors_[type]; + + // Check if there's a default platform cursor available. + base::Optional default_cursor = + factory_->GetDefaultCursor(type); + if (default_cursor) + return *default_cursor; + + // Loads the default Aura cursor bitmap for the cursor type. Falls back on + // pointer cursor if this fails. + PlatformCursor platform = CreateFallbackCursor(type); + if (!platform && type != mojom::CursorType::kPointer) { + platform = CursorFromType(mojom::CursorType::kPointer); + factory_->RefImageCursor(platform); + image_cursors_[type] = platform; + } + DCHECK(platform) << "Failed to load a fallback bitmap for cursor " << type; + return platform; +} + +// Gets default Aura cursor bitmap/hotspot and creates a PlatformCursor with it. +PlatformCursor CursorLoaderOzone::CreateFallbackCursor(mojom::CursorType type) { + int resource_id; + gfx::Point point; + if (ui::GetCursorDataFor(ui::CursorSize::kNormal, type, scale(), &resource_id, + &point)) { + LoadImageCursor(type, resource_id, point); + return image_cursors_[type]; + } + return nullptr; } CursorLoader* CursorLoader::Create() { diff --git a/chromium/ui/base/cursor/cursor_loader_ozone.h b/chromium/ui/base/cursor/cursor_loader_ozone.h index 9d561727761..ccd23a3c9e0 100644 --- a/chromium/ui/base/cursor/cursor_loader_ozone.h +++ b/chromium/ui/base/cursor/cursor_loader_ozone.h @@ -7,19 +7,17 @@ #include +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_loader.h" #include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" namespace ui { +class CursorFactory; -class CursorFactoryOzone; - -class UI_BASE_EXPORT CursorLoaderOzone : public CursorLoader { +class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoaderOzone : public CursorLoader { public: - // CursorLoaderOzone will use CursorFactoryOzone corresponding to the thread - // it was constructed on. CursorLoaderOzone(); ~CursorLoaderOzone() override; @@ -35,9 +33,12 @@ class UI_BASE_EXPORT CursorLoaderOzone : public CursorLoader { void SetPlatformCursor(gfx::NativeCursor* cursor) override; private: + PlatformCursor CursorFromType(mojom::CursorType type); + PlatformCursor CreateFallbackCursor(mojom::CursorType type); + // Pointers are owned by ResourceBundle and must not be freed here. std::map image_cursors_; - CursorFactoryOzone* factory_ = nullptr; + CursorFactory* factory_ = nullptr; DISALLOW_COPY_AND_ASSIGN(CursorLoaderOzone); }; diff --git a/chromium/ui/base/cursor/cursor_loader_win.cc b/chromium/ui/base/cursor/cursor_loader_win.cc index d981eb79cda..735568dddc0 100644 --- a/chromium/ui/base/cursor/cursor_loader_win.cc +++ b/chromium/ui/base/cursor/cursor_loader_win.cc @@ -7,7 +7,7 @@ #include #include "base/lazy_instance.h" -#include "base/strings/string16.h" +#include "base/notreached.h" #include "ui/base/cursor/cursor.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" #include "ui/resources/grit/ui_unscaled_resources.h" diff --git a/chromium/ui/base/cursor/cursor_loader_win.h b/chromium/ui/base/cursor/cursor_loader_win.h index f17ca9f965b..bf3ec63c961 100644 --- a/chromium/ui/base/cursor/cursor_loader_win.h +++ b/chromium/ui/base/cursor/cursor_loader_win.h @@ -5,13 +5,14 @@ #ifndef UI_BASE_CURSOR_CURSOR_LOADER_WIN_H_ #define UI_BASE_CURSOR_CURSOR_LOADER_WIN_H_ -#include "base/compiler_specific.h" +#include "base/component_export.h" #include "base/macros.h" +#include "base/strings/string16.h" #include "ui/base/cursor/cursor_loader.h" namespace ui { -class UI_BASE_EXPORT CursorLoaderWin : public CursorLoader { +class COMPONENT_EXPORT(UI_BASE_CURSOR) CursorLoaderWin : public CursorLoader { public: CursorLoaderWin(); ~CursorLoaderWin() override; diff --git a/chromium/ui/base/cursor/cursor_loader_x11.cc b/chromium/ui/base/cursor/cursor_loader_x11.cc deleted file mode 100644 index e0b52555d62..00000000000 --- a/chromium/ui/base/cursor/cursor_loader_x11.cc +++ /dev/null @@ -1,310 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/base/cursor/cursor_loader_x11.h" - -#include - -#include "base/check.h" -#include "base/notreached.h" -#include "build/build_config.h" -#include "skia/ext/image_operations.h" -#include "ui/base/cursor/cursor.h" -#include "ui/base/cursor/cursor_size.h" -#include "ui/base/cursor/cursor_util.h" -#include "ui/base/cursor/cursors_aura.h" -#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" -#include "ui/base/x/x11_util.h" -#include "ui/display/display.h" -#include "ui/gfx/geometry/point_conversions.h" -#include "ui/gfx/geometry/size_conversions.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/skbitmap_operations.h" -#include "ui/gfx/skia_util.h" - -namespace ui { - -namespace { - -// Load a cursor with a list of css names or shapes in order of decreasing -// priority. -::Cursor LoadFontCursor() { - return x11::None; -} - -template -::Cursor LoadFontCursor(int shape, Ts... ts); - -template -::Cursor LoadFontCursor(const char* name, Ts... ts) { - ::Cursor cursor = XcursorLibraryLoadCursor(gfx::GetXDisplay(), name); - if (cursor != x11::None) - return cursor; - return LoadFontCursor(ts...); -} - -template -::Cursor LoadFontCursor(int shape, Ts... ts) { - ::Cursor cursor = XCreateFontCursor(gfx::GetXDisplay(), shape); - if (cursor != x11::None) - return cursor; - return LoadFontCursor(ts...); -} - -::Cursor LoadFontCursorForCursorType(mojom::CursorType id) { - switch (id) { - case mojom::CursorType::kMiddlePanning: - return LoadFontCursor("all-scroll", XC_fleur); - case mojom::CursorType::kMiddlePanningVertical: - return LoadFontCursor("v-scroll"); - case mojom::CursorType::kMiddlePanningHorizontal: - return LoadFontCursor("h-scroll"); - case mojom::CursorType::kNone: - return LoadFontCursor("none"); - case mojom::CursorType::kGrab: - return LoadFontCursor("openhand", "grab"); - case mojom::CursorType::kGrabbing: - return LoadFontCursor("closedhand", "grabbing", XC_hand2); - case mojom::CursorType::kNull: - case mojom::CursorType::kPointer: - return LoadFontCursor("left_ptr", XC_left_ptr); - case mojom::CursorType::kMove: - return LoadFontCursor("all-scroll", XC_fleur); - case mojom::CursorType::kCross: - return LoadFontCursor("crosshair", XC_cross); - case mojom::CursorType::kHand: - return LoadFontCursor("pointer", "hand", XC_hand2); - case mojom::CursorType::kIBeam: - return LoadFontCursor("text", XC_xterm); - case mojom::CursorType::kProgress: - return LoadFontCursor("progress", "left_ptr_watch", XC_watch); - case mojom::CursorType::kWait: - return LoadFontCursor("wait", XC_watch); - case mojom::CursorType::kHelp: - return LoadFontCursor("help"); - case mojom::CursorType::kEastResize: - case mojom::CursorType::kEastPanning: - return LoadFontCursor("e-resize", XC_right_side); - case mojom::CursorType::kNorthResize: - case mojom::CursorType::kNorthPanning: - return LoadFontCursor("n-resize", XC_top_side); - case mojom::CursorType::kNorthEastResize: - case mojom::CursorType::kNorthEastPanning: - return LoadFontCursor("ne-resize", XC_top_right_corner); - case mojom::CursorType::kNorthWestResize: - case mojom::CursorType::kNorthWestPanning: - return LoadFontCursor("nw-resize", XC_top_left_corner); - case mojom::CursorType::kSouthResize: - case mojom::CursorType::kSouthPanning: - return LoadFontCursor("s-resize", XC_bottom_side); - case mojom::CursorType::kSouthEastResize: - case mojom::CursorType::kSouthEastPanning: - return LoadFontCursor("se-resize", XC_bottom_right_corner); - case mojom::CursorType::kSouthWestResize: - case mojom::CursorType::kSouthWestPanning: - return LoadFontCursor("sw-resize", XC_bottom_left_corner); - case mojom::CursorType::kWestResize: - case mojom::CursorType::kWestPanning: - return LoadFontCursor("w-resize", XC_right_side); - case mojom::CursorType::kNorthSouthResize: - return LoadFontCursor(XC_sb_v_double_arrow, "ns-resize"); - case mojom::CursorType::kEastWestResize: - return LoadFontCursor(XC_sb_h_double_arrow, "ew-resize"); - case mojom::CursorType::kColumnResize: - return LoadFontCursor("col-resize", XC_sb_h_double_arrow); - case mojom::CursorType::kRowResize: - return LoadFontCursor("row-resize", XC_sb_v_double_arrow); - case mojom::CursorType::kNorthEastSouthWestResize: - return LoadFontCursor("size_bdiag", "nesw-resize", "fd_double_arrow"); - case mojom::CursorType::kNorthWestSouthEastResize: - return LoadFontCursor("size_fdiag", "nwse-resize", "bd_double_arrow"); - case mojom::CursorType::kVerticalText: - return LoadFontCursor("vertical-text"); - case mojom::CursorType::kZoomIn: - return LoadFontCursor("zoom-in"); - case mojom::CursorType::kZoomOut: - return LoadFontCursor("zoom-out"); - case mojom::CursorType::kCell: - return LoadFontCursor("cell", XC_plus); - case mojom::CursorType::kContextMenu: - return LoadFontCursor("context-menu"); - case mojom::CursorType::kAlias: - return LoadFontCursor("alias"); - case mojom::CursorType::kNoDrop: - return LoadFontCursor("no-drop"); - case mojom::CursorType::kCopy: - return LoadFontCursor("copy"); - case mojom::CursorType::kNotAllowed: - return LoadFontCursor("not-allowed", "crossed_circle"); - case mojom::CursorType::kDndNone: - return LoadFontCursor("dnd-none", XC_hand2); - case mojom::CursorType::kDndMove: - return LoadFontCursor("dnd-move", XC_hand2); - case mojom::CursorType::kDndCopy: - return LoadFontCursor("dnd-copy", XC_hand2); - case mojom::CursorType::kDndLink: - return LoadFontCursor("dnd-link", XC_hand2); - case mojom::CursorType::kCustom: - NOTREACHED(); - return LoadFontCursor(); - } - NOTREACHED() << "Case not handled for " << static_cast(id); - return LoadFontCursor(); -} - -} // namespace - -CursorLoader* CursorLoader::Create() { - return new CursorLoaderX11; -} - -CursorLoaderX11::ImageCursor::ImageCursor(XcursorImage* x_image, - float scale, - display::Display::Rotation rotation) - : scale(scale), rotation(rotation) { - cursor = CreateReffedCustomXCursor(x_image); -} - -CursorLoaderX11::ImageCursor::~ImageCursor() { - UnrefCustomXCursor(cursor); -} - -CursorLoaderX11::CursorLoaderX11() - : display_(gfx::GetXDisplay()), - invisible_cursor_(CreateInvisibleCursor(), gfx::GetXDisplay()) { - auto* cursor_theme_manager = CursorThemeManagerLinux::GetInstance(); - if (cursor_theme_manager) - cursor_theme_observer_.Add(cursor_theme_manager); -} - -CursorLoaderX11::~CursorLoaderX11() { - UnloadAll(); -} - -void CursorLoaderX11::LoadImageCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot) { - SkBitmap bitmap; - gfx::Point hotspot = hot; - - GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap); - XcursorImage* x_image = SkBitmapToXcursorImage(bitmap, hotspot); - image_cursors_[id] = - std::make_unique(x_image, scale(), rotation()); -} - -void CursorLoaderX11::LoadAnimatedCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot, - int frame_delay_ms) { - std::vector bitmaps; - gfx::Point hotspot = hot; - - GetAnimatedCursorBitmaps(resource_id, scale(), rotation(), &hotspot, - &bitmaps); - - XcursorImages* x_images = XcursorImagesCreate(bitmaps.size()); - x_images->nimage = bitmaps.size(); - - for (unsigned int frame = 0; frame < bitmaps.size(); ++frame) { - XcursorImage* x_image = SkBitmapToXcursorImage(bitmaps[frame], hotspot); - x_image->delay = frame_delay_ms; - x_images->images[frame] = x_image; - } - - animated_cursors_[id] = std::make_pair( - XcursorImagesLoadCursor(gfx::GetXDisplay(), x_images), x_images); -} - -void CursorLoaderX11::UnloadAll() { - image_cursors_.clear(); - - // Free animated cursors and images. - for (const auto& cursor : animated_cursors_) { - XcursorImagesDestroy( - cursor.second.second); // also frees individual frames. - XFreeCursor(gfx::GetXDisplay(), cursor.second.first); - } -} - -void CursorLoaderX11::SetPlatformCursor(gfx::NativeCursor* cursor) { - DCHECK(cursor); - - if (*cursor == mojom::CursorType::kNone) { - cursor->SetPlatformCursor(invisible_cursor_.get()); - return; - } - - if (*cursor == mojom::CursorType::kCustom) - return; - - cursor->set_image_scale_factor(scale()); - cursor->SetPlatformCursor(CursorFromId(cursor->type())); -} - -const XcursorImage* CursorLoaderX11::GetXcursorImageForTest( - mojom::CursorType id) { - return test::GetCachedXcursorImage(image_cursors_[id]->cursor); -} - -void CursorLoaderX11::OnCursorThemeNameChanged( - const std::string& cursor_theme_name) { - XcursorSetTheme(display_, cursor_theme_name.c_str()); - ClearThemeCursors(); -} - -void CursorLoaderX11::OnCursorThemeSizeChanged(int cursor_theme_size) { - XcursorSetDefaultSize(display_, cursor_theme_size); - ClearThemeCursors(); -} - -bool CursorLoaderX11::IsImageCursor(gfx::NativeCursor native_cursor) { - mojom::CursorType type = native_cursor.type(); - return image_cursors_.count(type) || animated_cursors_.count(type); -} - -::Cursor CursorLoaderX11::CursorFromId(mojom::CursorType id) { - auto font_it = font_cursors_.find(id); - if (font_it != font_cursors_.end()) - return font_it->second; - auto image_it = image_cursors_.find(id); - if (image_it != image_cursors_.end()) { - if (image_it->second->scale == scale() && - image_it->second->rotation == rotation()) { - return image_it->second->cursor; - } else { - image_cursors_.erase(image_it); - } - } - - // First try to load the cursor directly. - ::Cursor cursor = LoadFontCursorForCursorType(id); - if (cursor != x11::None) { - font_cursors_[id] = cursor; - return cursor; - } - - // If the theme is missing the desired cursor, use a chromium-supplied - // fallback icon. - int resource_id; - gfx::Point point; - if (ui::GetCursorDataFor(ui::CursorSize::kNormal, id, scale(), &resource_id, - &point)) { - LoadImageCursor(id, resource_id, point); - return image_cursors_[id]->cursor; - } - - // As a last resort, return a left pointer. - cursor = XCreateFontCursor(display_, XC_left_ptr); - DCHECK(cursor); - font_cursors_[id] = cursor; - return cursor; -} - -void CursorLoaderX11::ClearThemeCursors() { - font_cursors_.clear(); - image_cursors_.clear(); -} - -} // namespace ui diff --git a/chromium/ui/base/cursor/cursor_loader_x11.h b/chromium/ui/base/cursor/cursor_loader_x11.h deleted file mode 100644 index 26870d09e03..00000000000 --- a/chromium/ui/base/cursor/cursor_loader_x11.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ -#define UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ - -#include - -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "base/scoped_observer.h" -#include "ui/base/cursor/cursor.h" -#include "ui/base/cursor/cursor_loader.h" -#include "ui/base/cursor/cursor_theme_manager_linux.h" -#include "ui/base/cursor/cursor_theme_manager_linux_observer.h" -#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" -#include "ui/base/ui_base_export.h" -#include "ui/base/x/x11_util.h" -#include "ui/gfx/x/x11.h" - -namespace ui { - -class UI_BASE_EXPORT CursorLoaderX11 : public CursorLoader, - public CursorThemeManagerLinuxObserver { - public: - CursorLoaderX11(); - ~CursorLoaderX11() override; - - // Overridden from CursorLoader: - void LoadImageCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot) override; - void LoadAnimatedCursor(mojom::CursorType id, - int resource_id, - const gfx::Point& hot, - int frame_delay_ms) override; - void UnloadAll() override; - void SetPlatformCursor(gfx::NativeCursor* cursor) override; - - const XcursorImage* GetXcursorImageForTest(mojom::CursorType id); - - protected: - // CursorThemeManagerLinux: - void OnCursorThemeNameChanged(const std::string& cursor_theme_name) override; - void OnCursorThemeSizeChanged(int cursor_theme_size) override; - - private: - struct ImageCursor { - ImageCursor(XcursorImage* x_image, - float scale, - display::Display::Rotation rotation); - ~ImageCursor(); - - ::Cursor cursor; - float scale; - display::Display::Rotation rotation; - }; - - // Returns true if we have an image resource loaded for the |native_cursor|. - bool IsImageCursor(gfx::NativeCursor native_cursor); - - // Loads a new cursor corresponding to |id|. - ::Cursor CursorFromId(mojom::CursorType id); - - void ClearThemeCursors(); - - XDisplay* display_; - - // A map from a cursor native type to X cursor. - std::map font_cursors_; - - // A map to hold all image cursors. It maps the cursor ID to the X Cursor, the - // display's scale factor, and the display's rotation. - std::map> image_cursors_; - - // A map to hold all animated cursors. It maps the cursor ID to the pair of - // the X Cursor and the corresponding XcursorImages. We need a pointer to the - // images so that we can free them on destruction. - std::map> - animated_cursors_; - - const XScopedCursor invisible_cursor_; - - ScopedObserver - cursor_theme_observer_{this}; - - DISALLOW_COPY_AND_ASSIGN(CursorLoaderX11); -}; - -} // namespace ui - -#endif // UI_BASE_CURSOR_CURSOR_LOADER_X11_H_ diff --git a/chromium/ui/base/cursor/cursor_lookup.h b/chromium/ui/base/cursor/cursor_lookup.h index 47aefe22f6c..82f908422a1 100644 --- a/chromium/ui/base/cursor/cursor_lookup.h +++ b/chromium/ui/base/cursor/cursor_lookup.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_CURSOR_CURSOR_LOOKUP_H_ #define UI_BASE_CURSOR_CURSOR_LOOKUP_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" class SkBitmap; @@ -16,9 +16,11 @@ class Point; namespace ui { class Cursor; -SkBitmap UI_BASE_EXPORT GetCursorBitmap(const Cursor& cursor); +COMPONENT_EXPORT(UI_BASE_CURSOR) +SkBitmap GetCursorBitmap(const Cursor& cursor); -gfx::Point UI_BASE_EXPORT GetCursorHotspot(const Cursor& cursor); +COMPONENT_EXPORT(UI_BASE_CURSOR) +gfx::Point GetCursorHotspot(const Cursor& cursor); } // namespace ui diff --git a/chromium/ui/base/cursor/cursor_ozone.cc b/chromium/ui/base/cursor/cursor_ozone.cc index c4ef8c4d45e..b41f4ca3b67 100644 --- a/chromium/ui/base/cursor/cursor_ozone.cc +++ b/chromium/ui/base/cursor/cursor_ozone.cc @@ -4,18 +4,18 @@ #include "ui/base/cursor/cursor.h" -#include "ui/ozone/public/cursor_factory_ozone.h" +#include "ui/base/cursor/cursor_factory.h" namespace ui { void Cursor::RefCustomCursor() { if (platform_cursor_) - CursorFactoryOzone::GetInstance()->RefImageCursor(platform_cursor_); + CursorFactory::GetInstance()->RefImageCursor(platform_cursor_); } void Cursor::UnrefCustomCursor() { if (platform_cursor_) - CursorFactoryOzone::GetInstance()->UnrefImageCursor(platform_cursor_); + CursorFactory::GetInstance()->UnrefImageCursor(platform_cursor_); } } // namespace ui diff --git a/chromium/ui/base/cursor/cursor_theme_manager.cc b/chromium/ui/base/cursor/cursor_theme_manager.cc new file mode 100644 index 00000000000..665725a1c27 --- /dev/null +++ b/chromium/ui/base/cursor/cursor_theme_manager.cc @@ -0,0 +1,47 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/cursor/cursor_theme_manager.h" + +#include "base/check.h" +#include "base/check_op.h" + +namespace ui { + +namespace { + +CursorThemeManager* g_instance = nullptr; + +} + +CursorThemeManager::~CursorThemeManager() { + DCHECK_EQ(g_instance, this); + g_instance = nullptr; +} + +// static +CursorThemeManager* CursorThemeManager::GetInstance() { + return g_instance; +} + +void CursorThemeManager::AddObserver(CursorThemeManagerObserver* observer) { + cursor_theme_observers_.AddObserver(observer); + std::string name = GetCursorThemeName(); + if (!name.empty()) + observer->OnCursorThemeNameChanged(name); + int size = GetCursorThemeSize(); + if (size) + observer->OnCursorThemeSizeChanged(size); +} + +void CursorThemeManager::RemoveObserver(CursorThemeManagerObserver* observer) { + cursor_theme_observers_.RemoveObserver(observer); +} + +CursorThemeManager::CursorThemeManager() { + DCHECK(!g_instance); + g_instance = this; +} + +} // namespace ui diff --git a/chromium/ui/base/cursor/cursor_theme_manager.h b/chromium/ui/base/cursor/cursor_theme_manager.h new file mode 100644 index 00000000000..a6d09f04945 --- /dev/null +++ b/chromium/ui/base/cursor/cursor_theme_manager.h @@ -0,0 +1,46 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_CURSOR_CURSOR_THEME_MANAGER_H_ +#define UI_BASE_CURSOR_CURSOR_THEME_MANAGER_H_ + +#include + +#include "base/observer_list.h" +#include "ui/base/cursor/cursor_theme_manager_observer.h" + +namespace ui { + +class CursorThemeManager { + public: + CursorThemeManager(const CursorThemeManager&) = delete; + CursorThemeManager& operator=(const CursorThemeManager&) = delete; + virtual ~CursorThemeManager(); + + static CursorThemeManager* GetInstance(); + + // Adds |observer| and makes initial OnCursorThemNameChanged() and/or + // OnCursorThemeSizeChanged() calls if the respective settings were set. + void AddObserver(CursorThemeManagerObserver* observer); + + void RemoveObserver(CursorThemeManagerObserver* observer); + + protected: + CursorThemeManager(); + + const base::ObserverList& + cursor_theme_observers() { + return cursor_theme_observers_; + } + + virtual std::string GetCursorThemeName() = 0; + virtual int GetCursorThemeSize() = 0; + + private: + base::ObserverList cursor_theme_observers_; +}; + +} // namespace ui + +#endif // UI_BASE_CURSOR_CURSOR_THEME_MANAGER_H_ diff --git a/chromium/ui/base/cursor/cursor_theme_manager_linux.cc b/chromium/ui/base/cursor/cursor_theme_manager_linux.cc deleted file mode 100644 index f825b745f5d..00000000000 --- a/chromium/ui/base/cursor/cursor_theme_manager_linux.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/base/cursor/cursor_theme_manager_linux.h" - -namespace ui { - -// static -CursorThemeManagerLinux* CursorThemeManagerLinux::instance_ = nullptr; - -// static -void CursorThemeManagerLinux::SetInstance(CursorThemeManagerLinux* instance) { - instance_ = instance; -} - -// static -CursorThemeManagerLinux* CursorThemeManagerLinux::GetInstance() { - return instance_; -} - -CursorThemeManagerLinux::CursorThemeManagerLinux() = default; - -CursorThemeManagerLinux::~CursorThemeManagerLinux() = default; - -void CursorThemeManagerLinux::AddObserver( - CursorThemeManagerLinuxObserver* observer) { - cursor_theme_observers_.AddObserver(observer); - std::string name = GetCursorThemeName(); - if (!name.empty()) - observer->OnCursorThemeNameChanged(name); - int size = GetCursorThemeSize(); - if (size) - observer->OnCursorThemeSizeChanged(size); -} - -void CursorThemeManagerLinux::RemoveObserver( - CursorThemeManagerLinuxObserver* observer) { - cursor_theme_observers_.RemoveObserver(observer); -} - -} // namespace ui diff --git a/chromium/ui/base/cursor/cursor_theme_manager_linux.h b/chromium/ui/base/cursor/cursor_theme_manager_linux.h deleted file mode 100644 index 464d397cec5..00000000000 --- a/chromium/ui/base/cursor/cursor_theme_manager_linux.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_CURSOR_CURSOR_THEME_MANAGER_LINUX_H_ -#define UI_BASE_CURSOR_CURSOR_THEME_MANAGER_LINUX_H_ - -#include - -#include "base/macros.h" -#include "base/observer_list.h" -#include "ui/base/cursor/cursor_theme_manager_linux_observer.h" -#include "ui/base/ui_base_export.h" - -namespace ui { - -class UI_BASE_EXPORT CursorThemeManagerLinux { - public: - virtual ~CursorThemeManagerLinux(); - - static void SetInstance(CursorThemeManagerLinux* instance); - - static CursorThemeManagerLinux* GetInstance(); - - // Adds |observer| and makes initial OnCursorThemNameChanged() and/or - // OnCursorThemeSizeChanged() calls if the respective settings were set. - void AddObserver(CursorThemeManagerLinuxObserver* observer); - - void RemoveObserver(CursorThemeManagerLinuxObserver* observer); - - protected: - CursorThemeManagerLinux(); - - const base::ObserverList& - cursor_theme_observers() { - return cursor_theme_observers_; - } - - virtual std::string GetCursorThemeName() = 0; - virtual int GetCursorThemeSize() = 0; - - private: - static CursorThemeManagerLinux* instance_; - - base::ObserverList cursor_theme_observers_; - - DISALLOW_COPY_AND_ASSIGN(CursorThemeManagerLinux); -}; - -} // namespace ui - -#endif // UI_BASE_CURSOR_CURSOR_THEME_MANAGER_LINUX_H_ diff --git a/chromium/ui/base/cursor/cursor_theme_manager_linux_observer.h b/chromium/ui/base/cursor/cursor_theme_manager_linux_observer.h deleted file mode 100644 index 73a3b42f343..00000000000 --- a/chromium/ui/base/cursor/cursor_theme_manager_linux_observer.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_CURSOR_CURSOR_THEME_MANAGER_LINUX_OBSERVER_H_ -#define UI_BASE_CURSOR_CURSOR_THEME_MANAGER_LINUX_OBSERVER_H_ - -#include - -#include "base/observer_list_types.h" -#include "ui/base/ui_base_export.h" - -namespace ui { - -class UI_BASE_EXPORT CursorThemeManagerLinuxObserver - : public base::CheckedObserver { - public: - // |cursor_theme_name| will be nonempty. - virtual void OnCursorThemeNameChanged( - const std::string& cursor_theme_name) = 0; - - // |cursor_theme_size| will be nonzero. - virtual void OnCursorThemeSizeChanged(int cursor_theme_size) = 0; - - protected: - ~CursorThemeManagerLinuxObserver() override = default; -}; - -} // namespace ui - -#endif // UI_BASE_CURSOR_CURSOR_THEME_MANAGER_LINUX_OBSERVER_H_ diff --git a/chromium/ui/base/cursor/cursor_theme_manager_observer.h b/chromium/ui/base/cursor/cursor_theme_manager_observer.h new file mode 100644 index 00000000000..028a8bb7dfe --- /dev/null +++ b/chromium/ui/base/cursor/cursor_theme_manager_observer.h @@ -0,0 +1,29 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_CURSOR_CURSOR_THEME_MANAGER_OBSERVER_H_ +#define UI_BASE_CURSOR_CURSOR_THEME_MANAGER_OBSERVER_H_ + +#include + +#include "base/observer_list_types.h" + +namespace ui { + +class CursorThemeManagerObserver : public base::CheckedObserver { + public: + // |cursor_theme_name| will be nonempty. + virtual void OnCursorThemeNameChanged( + const std::string& cursor_theme_name) = 0; + + // |cursor_theme_size| will be nonzero. + virtual void OnCursorThemeSizeChanged(int cursor_theme_size) = 0; + + protected: + ~CursorThemeManagerObserver() override = default; +}; + +} // namespace ui + +#endif // UI_BASE_CURSOR_CURSOR_THEME_MANAGER_OBSERVER_H_ diff --git a/chromium/ui/base/cursor/cursor_unittest.cc b/chromium/ui/base/cursor/cursor_unittest.cc index ef2d9e1e58f..d69ecfcc2cd 100644 --- a/chromium/ui/base/cursor/cursor_unittest.cc +++ b/chromium/ui/base/cursor/cursor_unittest.cc @@ -4,12 +4,10 @@ #include "ui/base/cursor/cursor.h" -#include - #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/cursor/cursor_lookup.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" +#include "ui/gfx/geometry/point.h" #include "ui/gfx/skia_util.h" namespace ui { @@ -38,22 +36,21 @@ TEST(CursorTest, CustomType) { const gfx::Point kHotspot = gfx::Point(5, 2); cursor.set_custom_hotspot(kHotspot); - EXPECT_EQ(kHotspot, GetCursorHotspot(cursor)); + EXPECT_EQ(kHotspot, cursor.custom_hotspot()); SkBitmap bitmap; bitmap.allocN32Pixels(10, 10); bitmap.eraseColor(SK_ColorRED); cursor.set_custom_bitmap(bitmap); - EXPECT_EQ(bitmap.getGenerationID(), - GetCursorBitmap(cursor).getGenerationID()); - EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap, GetCursorBitmap(cursor))); + EXPECT_EQ(bitmap.getGenerationID(), cursor.custom_bitmap().getGenerationID()); + EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap, cursor.custom_bitmap())); Cursor copy(cursor); - EXPECT_EQ(GetCursorBitmap(cursor).getGenerationID(), - GetCursorBitmap(copy).getGenerationID()); + EXPECT_EQ(cursor.custom_bitmap().getGenerationID(), + copy.custom_bitmap().getGenerationID()); EXPECT_TRUE( - gfx::BitmapsAreEqual(GetCursorBitmap(cursor), GetCursorBitmap(copy))); + gfx::BitmapsAreEqual(cursor.custom_bitmap(), copy.custom_bitmap())); EXPECT_EQ(cursor, copy); } @@ -71,10 +68,10 @@ TEST(CursorTest, CustomTypeComparesBitmapPixels) { bitmap2.eraseColor(SK_ColorRED); cursor2.set_custom_bitmap(bitmap2); - EXPECT_NE(GetCursorBitmap(cursor1).getGenerationID(), - GetCursorBitmap(cursor2).getGenerationID()); + EXPECT_NE(cursor1.custom_bitmap().getGenerationID(), + cursor2.custom_bitmap().getGenerationID()); EXPECT_TRUE( - gfx::BitmapsAreEqual(GetCursorBitmap(cursor1), GetCursorBitmap(cursor2))); + gfx::BitmapsAreEqual(cursor1.custom_bitmap(), cursor2.custom_bitmap())); EXPECT_EQ(cursor1, cursor2); } diff --git a/chromium/ui/base/cursor/cursor_util.cc b/chromium/ui/base/cursor/cursor_util.cc index 4af26e57833..a19a4ddcf1e 100644 --- a/chromium/ui/base/cursor/cursor_util.cc +++ b/chromium/ui/base/cursor/cursor_util.cc @@ -6,8 +6,11 @@ #include "base/check_op.h" #include "base/notreached.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point_conversions.h" +#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size_conversions.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/skbitmap_operations.h" diff --git a/chromium/ui/base/cursor/cursor_util.h b/chromium/ui/base/cursor/cursor_util.h index fc93f2150f4..1fe3277c509 100644 --- a/chromium/ui/base/cursor/cursor_util.h +++ b/chromium/ui/base/cursor/cursor_util.h @@ -7,22 +7,25 @@ #include -#include "base/compiler_specific.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #include "ui/display/display.h" -#include "ui/gfx/geometry/point.h" + +class SkBitmap; + +namespace gfx { +class Point; +} namespace ui { // Scale and rotate the cursor's bitmap and hotpoint. // |bitmap_in_out| and |hotpoint_in_out| are used as // both input and output. -UI_BASE_EXPORT void ScaleAndRotateCursorBitmapAndHotpoint( - float scale, - display::Display::Rotation rotation, - SkBitmap* bitmap_in_out, - gfx::Point* hotpoint_in_out); +COMPONENT_EXPORT(UI_BASE_CURSOR) +void ScaleAndRotateCursorBitmapAndHotpoint(float scale, + display::Display::Rotation rotation, + SkBitmap* bitmap_in_out, + gfx::Point* hotpoint_in_out); // Helpers for CursorLoader. void GetImageCursorBitmap(int resource_id, diff --git a/chromium/ui/base/cursor/cursor_util_unittest.cc b/chromium/ui/base/cursor/cursor_util_unittest.cc index 1e2d55f6385..89cb58fc873 100644 --- a/chromium/ui/base/cursor/cursor_util_unittest.cc +++ b/chromium/ui/base/cursor/cursor_util_unittest.cc @@ -6,6 +6,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/geometry/point.h" namespace ui { namespace { diff --git a/chromium/ui/base/cursor/cursor_x11.cc b/chromium/ui/base/cursor/cursor_x11.cc deleted file mode 100644 index edf6c9bb6ba..00000000000 --- a/chromium/ui/base/cursor/cursor_x11.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/base/cursor/cursor.h" - -#include "ui/base/x/x11_util.h" - -namespace ui { - -void Cursor::RefCustomCursor() { - if (platform_cursor_) - ui::RefCustomXCursor(platform_cursor_); -} - -void Cursor::UnrefCustomCursor() { - if (platform_cursor_) - ui::UnrefCustomXCursor(platform_cursor_); -} - -} // namespace ui diff --git a/chromium/ui/base/cursor/cursors_aura.cc b/chromium/ui/base/cursor/cursors_aura.cc index 2a7ba7784c1..710fb8dba11 100644 --- a/chromium/ui/base/cursor/cursors_aura.cc +++ b/chromium/ui/base/cursor/cursors_aura.cc @@ -9,6 +9,7 @@ #include "base/stl_util.h" #include "build/build_config.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_size.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" #include "ui/base/resource/resource_bundle.h" @@ -22,6 +23,7 @@ #endif namespace ui { + namespace { struct HotPoint { @@ -282,120 +284,6 @@ bool SearchTable(const CursorData* table, } // namespace -const char* CursorCssNameFromId(mojom::CursorType id) { - switch (id) { - case mojom::CursorType::kMiddlePanning: - return "all-scroll"; - case mojom::CursorType::kMiddlePanningVertical: - return "v-scroll"; - case mojom::CursorType::kMiddlePanningHorizontal: - return "h-scroll"; - case mojom::CursorType::kEastPanning: - return "e-resize"; - case mojom::CursorType::kNorthPanning: - return "n-resize"; - case mojom::CursorType::kNorthEastPanning: - return "ne-resize"; - case mojom::CursorType::kNorthWestPanning: - return "nw-resize"; - case mojom::CursorType::kSouthPanning: - return "s-resize"; - case mojom::CursorType::kSouthEastPanning: - return "se-resize"; - case mojom::CursorType::kSouthWestPanning: - return "sw-resize"; - case mojom::CursorType::kWestPanning: - return "w-resize"; - case mojom::CursorType::kNone: - return "none"; - case mojom::CursorType::kGrab: - return "grab"; - case mojom::CursorType::kGrabbing: - return "grabbing"; - case mojom::CursorType::kNull: - return "left_ptr"; - case mojom::CursorType::kPointer: - return "left_ptr"; - case mojom::CursorType::kMove: - // Returning "move" is the correct thing here, but Blink doesn't - // make a distinction between move and all-scroll. Other - // platforms use a cursor more consistent with all-scroll, so - // use that. - return "all-scroll"; - case mojom::CursorType::kCross: - return "crosshair"; - case mojom::CursorType::kHand: - return "pointer"; - case mojom::CursorType::kIBeam: - return "text"; - case mojom::CursorType::kProgress: - return "progress"; - case mojom::CursorType::kWait: - return "wait"; - case mojom::CursorType::kHelp: - return "help"; - case mojom::CursorType::kEastResize: - return "e-resize"; - case mojom::CursorType::kNorthResize: - return "n-resize"; - case mojom::CursorType::kNorthEastResize: - return "ne-resize"; - case mojom::CursorType::kNorthWestResize: - return "nw-resize"; - case mojom::CursorType::kSouthResize: - return "s-resize"; - case mojom::CursorType::kSouthEastResize: - return "se-resize"; - case mojom::CursorType::kSouthWestResize: - return "sw-resize"; - case mojom::CursorType::kWestResize: - return "w-resize"; - case mojom::CursorType::kNorthSouthResize: - return "ns-resize"; - case mojom::CursorType::kEastWestResize: - return "ew-resize"; - case mojom::CursorType::kColumnResize: - return "col-resize"; - case mojom::CursorType::kRowResize: - return "row-resize"; - case mojom::CursorType::kNorthEastSouthWestResize: - return "nesw-resize"; - case mojom::CursorType::kNorthWestSouthEastResize: - return "nwse-resize"; - case mojom::CursorType::kVerticalText: - return "vertical-text"; - case mojom::CursorType::kZoomIn: - return "zoom-in"; - case mojom::CursorType::kZoomOut: - return "zoom-out"; - case mojom::CursorType::kCell: - return "cell"; - case mojom::CursorType::kContextMenu: - return "context-menu"; - case mojom::CursorType::kAlias: - return "alias"; - case mojom::CursorType::kNoDrop: - return "no-drop"; - case mojom::CursorType::kCopy: - return "copy"; - case mojom::CursorType::kNotAllowed: - return "not-allowed"; - case mojom::CursorType::kDndNone: - return "dnd-none"; - case mojom::CursorType::kDndMove: - return "dnd-move"; - case mojom::CursorType::kDndCopy: - return "dnd-copy"; - case mojom::CursorType::kDndLink: - return "dnd-link"; - case mojom::CursorType::kCustom: - NOTREACHED(); - return "left_ptr"; - } - NOTREACHED() << "Case not handled for " << static_cast(id); - return "left_ptr"; -} - bool GetCursorDataFor(CursorSize cursor_size, mojom::CursorType id, float scale_factor, diff --git a/chromium/ui/base/cursor/cursors_aura.h b/chromium/ui/base/cursor/cursors_aura.h index 778a5d3c871..cc82d976546 100644 --- a/chromium/ui/base/cursor/cursors_aura.h +++ b/chromium/ui/base/cursor/cursors_aura.h @@ -5,9 +5,8 @@ #ifndef UI_BASE_CURSOR_CURSORS_AURA_H_ #define UI_BASE_CURSOR_CURSORS_AURA_H_ -#include "ui/base/cursor/cursor.h" +#include "base/component_export.h" #include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" -#include "ui/base/ui_base_export.h" class SkBitmap; @@ -16,29 +15,29 @@ class Point; } namespace ui { +class Cursor; enum class CursorSize; const int kAnimatedCursorFrameDelayMs = 25; -// Returns CSS cursor name from an Aura cursor ID. -UI_BASE_EXPORT const char* CursorCssNameFromId(mojom::CursorType id); - // Returns data about |id|, where id is a cursor constant like // ui::mojom::CursorType::kHelp. The IDR will be placed in |resource_id| and // the hotspots for the different DPIs will be placed in |hot_1x| and // |hot_2x|. Returns false if |id| is invalid. -UI_BASE_EXPORT bool GetCursorDataFor(CursorSize cursor_size, - mojom::CursorType id, - float scale_factor, - int* resource_id, - gfx::Point* point); +COMPONENT_EXPORT(UI_BASE_CURSOR) +bool GetCursorDataFor(CursorSize cursor_size, + mojom::CursorType id, + float scale_factor, + int* resource_id, + gfx::Point* point); // Like above, but for animated cursors. -UI_BASE_EXPORT bool GetAnimatedCursorDataFor(CursorSize cursor_size, - mojom::CursorType id, - float scale_factor, - int* resource_id, - gfx::Point* point); +COMPONENT_EXPORT(UI_BASE_CURSOR) +bool GetAnimatedCursorDataFor(CursorSize cursor_size, + mojom::CursorType id, + float scale_factor, + int* resource_id, + gfx::Point* point); SkBitmap GetDefaultBitmap(const Cursor& cursor); diff --git a/chromium/ui/base/cursor/image_cursors.cc b/chromium/ui/base/cursor/image_cursors.cc index 4612bedb350..42fd3249684 100644 --- a/chromium/ui/base/cursor/image_cursors.cc +++ b/chromium/ui/base/cursor/image_cursors.cc @@ -4,25 +4,17 @@ #include "ui/base/cursor/image_cursors.h" -#include -#include - #include "base/check.h" -#include "base/notreached.h" -#include "base/stl_util.h" -#include "base/strings/string16.h" -#include "ui/base/cursor/cursor.h" #include "ui/base/cursor/cursor_loader.h" #include "ui/base/cursor/cursors_aura.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" -#include "ui/display/display.h" #include "ui/gfx/geometry/point.h" namespace ui { namespace { -const mojom::CursorType kImageCursorIds[] = { +constexpr mojom::CursorType kImageCursorIds[] = { mojom::CursorType::kNull, mojom::CursorType::kPointer, mojom::CursorType::kNoDrop, @@ -57,49 +49,30 @@ const mojom::CursorType kImageCursorIds[] = { mojom::CursorType::kGrabbing, }; -const mojom::CursorType kAnimatedCursorIds[] = {mojom::CursorType::kWait, - mojom::CursorType::kProgress}; +constexpr mojom::CursorType kAnimatedCursorIds[] = { + mojom::CursorType::kWait, mojom::CursorType::kProgress}; } // namespace -ImageCursors::ImageCursors() : cursor_size_(CursorSize::kNormal) {} +ImageCursors::ImageCursors() + : cursor_loader_(CursorLoader::Create()), + cursor_size_(CursorSize::kNormal) {} -ImageCursors::~ImageCursors() { -} - -void ImageCursors::Initialize() { - if (!cursor_loader_) - cursor_loader_.reset(CursorLoader::Create()); -} +ImageCursors::~ImageCursors() = default; float ImageCursors::GetScale() const { - if (!cursor_loader_) { - NOTREACHED(); - // Returning default on release build as it's not serious enough to crash - // even if this ever happens. - return 1.0f; - } return cursor_loader_->scale(); } display::Display::Rotation ImageCursors::GetRotation() const { - if (!cursor_loader_) { - NOTREACHED(); - // Returning default on release build as it's not serious enough to crash - // even if this ever happens. - return display::Display::ROTATE_0; - } return cursor_loader_->rotation(); } bool ImageCursors::SetDisplay(const display::Display& display, float scale_factor) { - if (!cursor_loader_) { - cursor_loader_.reset(CursorLoader::Create()); - } else if (cursor_loader_->rotation() == display.panel_rotation() && - cursor_loader_->scale() == scale_factor) { + if (cursor_loader_->rotation() == display.panel_rotation() && + cursor_loader_->scale() == scale_factor) return false; - } cursor_loader_->set_rotation(display.panel_rotation()); cursor_loader_->set_scale(scale_factor); @@ -112,25 +85,21 @@ void ImageCursors::ReloadCursors() { cursor_loader_->UnloadAll(); - for (size_t i = 0; i < base::size(kImageCursorIds); ++i) { + for (auto cursor_id : kImageCursorIds) { int resource_id = -1; gfx::Point hot_point; - bool success = - GetCursorDataFor(cursor_size_, kImageCursorIds[i], device_scale_factor, - &resource_id, &hot_point); + bool success = GetCursorDataFor( + cursor_size_, cursor_id, device_scale_factor, &resource_id, &hot_point); DCHECK(success); - cursor_loader_->LoadImageCursor(kImageCursorIds[i], resource_id, hot_point); + cursor_loader_->LoadImageCursor(cursor_id, resource_id, hot_point); } - for (size_t i = 0; i < base::size(kAnimatedCursorIds); ++i) { + for (auto cursor_id : kAnimatedCursorIds) { int resource_id = -1; gfx::Point hot_point; - bool success = - GetAnimatedCursorDataFor(cursor_size_, kAnimatedCursorIds[i], - device_scale_factor, &resource_id, &hot_point); + bool success = GetAnimatedCursorDataFor( + cursor_size_, cursor_id, device_scale_factor, &resource_id, &hot_point); DCHECK(success); - cursor_loader_->LoadAnimatedCursor(kAnimatedCursorIds[i], - resource_id, - hot_point, + cursor_loader_->LoadAnimatedCursor(cursor_id, resource_id, hot_point, kAnimatedCursorFrameDelayMs); } } @@ -141,16 +110,11 @@ void ImageCursors::SetCursorSize(CursorSize cursor_size) { cursor_size_ = cursor_size; - if (cursor_loader_.get()) - ReloadCursors(); + ReloadCursors(); } void ImageCursors::SetPlatformCursor(gfx::NativeCursor* cursor) { cursor_loader_->SetPlatformCursor(cursor); } -base::WeakPtr ImageCursors::GetWeakPtr() { - return weak_ptr_factory_.GetWeakPtr(); -} - } // namespace ui diff --git a/chromium/ui/base/cursor/image_cursors.h b/chromium/ui/base/cursor/image_cursors.h index 0855bfff15e..b5b5ec274dd 100644 --- a/chromium/ui/base/cursor/image_cursors.h +++ b/chromium/ui/base/cursor/image_cursors.h @@ -7,12 +7,8 @@ #include -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "base/strings/string16.h" -#include "ui/base/cursor/cursor.h" +#include "base/component_export.h" #include "ui/base/cursor/cursor_size.h" -#include "ui/base/ui_base_export.h" #include "ui/display/display.h" #include "ui/gfx/native_widget_types.h" @@ -22,19 +18,13 @@ class CursorLoader; // A utility class that provides cursors for NativeCursors for which we have // image resources. -class UI_BASE_EXPORT ImageCursors { +class COMPONENT_EXPORT(UI_BASE_CURSOR) ImageCursors { public: ImageCursors(); + ImageCursors(const ImageCursors&) = delete; + ImageCursors& operator=(const ImageCursors&) = delete; ~ImageCursors(); - // Creates the |cursor_loader_|. This is optional as |cursor_loader_| is - // lazily created if Initialize() isn't explictly called. - // However note that it matters which thread is used to create - // |cursor_loader_| (see CursorLoaderOzone, crbug.com/741106). Thus explicit - // call to Initialize may be useful to ensure initialization happens on the - // right thread. - void Initialize(); - // Returns the scale and rotation of the currently loaded cursor. float GetScale() const; display::Display::Rotation GetRotation() const; @@ -49,17 +39,12 @@ class UI_BASE_EXPORT ImageCursors { // Sets the platform cursor based on the native type of |cursor|. void SetPlatformCursor(gfx::NativeCursor* cursor); - base::WeakPtr GetWeakPtr(); - private: // Reloads the all loaded cursors in the cursor loader. void ReloadCursors(); std::unique_ptr cursor_loader_; CursorSize cursor_size_; - base::WeakPtrFactory weak_ptr_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(ImageCursors); }; } // namespace ui diff --git a/chromium/ui/base/cursor/mojom/BUILD.gn b/chromium/ui/base/cursor/mojom/BUILD.gn index 042d2160861..588e828c29d 100644 --- a/chromium/ui/base/cursor/mojom/BUILD.gn +++ b/chromium/ui/base/cursor/mojom/BUILD.gn @@ -33,7 +33,7 @@ source_set("mojom_traits") { ] public_deps = [ ":mojom_shared", - "//ui/base/cursor", + "//ui/base/cursor:cursor_base", ] deps = [ "//skia", @@ -56,7 +56,7 @@ source_set("unittests") { ":mojom_traits", "//testing/gtest", "//ui/base", - "//ui/base/cursor", + "//ui/base/cursor:cursor_base", "//ui/gfx:geometry_skia", "//ui/gfx/geometry/mojom:mojom_traits", ] diff --git a/chromium/ui/base/cursor/mojom/cursor_mojom_traits_unittest.cc b/chromium/ui/base/cursor/mojom/cursor_mojom_traits_unittest.cc index d3b1aee2f12..88f888b2709 100644 --- a/chromium/ui/base/cursor/mojom/cursor_mojom_traits_unittest.cc +++ b/chromium/ui/base/cursor/mojom/cursor_mojom_traits_unittest.cc @@ -7,7 +7,6 @@ #include "skia/public/mojom/bitmap_skbitmap_mojom_traits.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/cursor/cursor.h" -#include "ui/base/cursor/cursor_lookup.h" #include "ui/base/cursor/mojom/cursor.mojom.h" #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" #include "ui/gfx/geometry/mojom/geometry_mojom_traits.h" @@ -59,18 +58,18 @@ TEST_F(CursorStructTraitsTest, TestBitmapCursor) { EXPECT_EQ(ui::mojom::CursorType::kCustom, output.type()); EXPECT_EQ(kScale, output.image_scale_factor()); - EXPECT_EQ(kHotspot, GetCursorHotspot(output)); + EXPECT_EQ(kHotspot, output.custom_hotspot()); // Even though the pixel data is the same, the bitmap generation ids differ. EXPECT_TRUE( - gfx::BitmapsAreEqual(GetCursorBitmap(input), GetCursorBitmap(output))); - EXPECT_NE(GetCursorBitmap(input).getGenerationID(), - GetCursorBitmap(output).getGenerationID()); + gfx::BitmapsAreEqual(input.custom_bitmap(), output.custom_bitmap())); + EXPECT_NE(input.custom_bitmap().getGenerationID(), + output.custom_bitmap().getGenerationID()); // Make a copy of output; the bitmap generation ids should be the same. ui::Cursor copy = output; - EXPECT_EQ(GetCursorBitmap(output).getGenerationID(), - GetCursorBitmap(copy).getGenerationID()); + EXPECT_EQ(output.custom_bitmap().getGenerationID(), + copy.custom_bitmap().getGenerationID()); EXPECT_EQ(input, output); } @@ -88,7 +87,7 @@ TEST_F(CursorStructTraitsTest, TestEmptyCursor) { ui::Cursor output; ASSERT_TRUE(EchoCursor(input, &output)); - EXPECT_TRUE(GetCursorBitmap(output).empty()); + EXPECT_TRUE(output.custom_bitmap().empty()); } // Test that various device scale factors are passed correctly over the wire. diff --git a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc index 44037bc6142..e86f70ea603 100644 --- a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc +++ b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.cc @@ -7,10 +7,6 @@ #include #include "base/check_op.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/base/cursor/cursor_lookup.h" -#include "ui/base/cursor/cursors_aura.h" -#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h" namespace ui { @@ -24,20 +20,6 @@ PlatformCursor ToPlatformCursor(BitmapCursorOzone* cursor) { return static_cast(cursor); } -scoped_refptr CreateDefaultBitmapCursor( - mojom::CursorType type) { - Cursor cursor(type); - // Ozone must honor the lowest possible scale value, which is 1.0f. Otherwise, - // it can happen that cursor chooses wrong hotspots if max scaling value is - // set to 200p, for example. - cursor.set_image_scale_factor(1.0f); - SkBitmap bitmap = GetCursorBitmap(cursor); - gfx::Point hotspot = GetCursorHotspot(cursor); - if (!bitmap.isNull()) - return new BitmapCursorOzone(bitmap, hotspot); - return nullptr; -} - } // namespace BitmapCursorOzone::BitmapCursorOzone(const SkBitmap& bitmap, @@ -89,15 +71,16 @@ scoped_refptr BitmapCursorFactoryOzone::GetBitmapCursor( return base::WrapRefCounted(ToBitmapCursorOzone(platform_cursor)); } -PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor( +base::Optional BitmapCursorFactoryOzone::GetDefaultCursor( mojom::CursorType type) { - return GetDefaultCursorInternal(type).get(); + if (type == mojom::CursorType::kNone) + return nullptr; // nullptr is used for the hidden cursor. + return base::nullopt; } PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( const SkBitmap& bitmap, - const gfx::Point& hotspot, - float bitmap_dpi) { + const gfx::Point& hotspot) { BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); cursor->AddRef(); // Balanced by UnrefImageCursor. return ToPlatformCursor(cursor); @@ -106,8 +89,7 @@ PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor( const std::vector& bitmaps, const gfx::Point& hotspot, - int frame_delay_ms, - float bitmap_dpi) { + int frame_delay_ms) { DCHECK_LT(0U, bitmaps.size()); BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmaps, hotspot, frame_delay_ms); @@ -123,23 +105,4 @@ void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { ToBitmapCursorOzone(cursor)->Release(); } -scoped_refptr -BitmapCursorFactoryOzone::GetDefaultCursorInternal(mojom::CursorType type) { - if (type == mojom::CursorType::kNone) - return nullptr; // Null is used for hidden cursor. - - if (!default_cursors_.count(type)) { - // Create new image cursor from default aura bitmap for this type. We hold a - // ref forever because clients do not do refcounting for default cursors. - scoped_refptr cursor = CreateDefaultBitmapCursor(type); - if (!cursor.get() && type != mojom::CursorType::kPointer) - cursor = GetDefaultCursorInternal(mojom::CursorType::kPointer); - DCHECK(cursor.get()) << "Failed to load default cursor bitmap"; - default_cursors_[type] = cursor; - } - - // Returned owned default cursor for this type. - return default_cursors_[type]; -} - } // namespace ui diff --git a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h index 95ed10b051b..b489e099ad0 100644 --- a/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h +++ b/chromium/ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h @@ -5,21 +5,20 @@ #ifndef UI_BASE_CURSOR_OZONE_BITMAP_CURSOR_FACTORY_OZONE_H_ #define UI_BASE_CURSOR_OZONE_BITMAP_CURSOR_FACTORY_OZONE_H_ -#include +#include +#include "base/component_export.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/cursor/cursor.h" -#include "ui/base/cursor/mojom/cursor_type.mojom-forward.h" -#include "ui/base/ui_base_export.h" +#include "ui/base/cursor/cursor_factory.h" #include "ui/gfx/geometry/point.h" -#include "ui/ozone/public/cursor_factory_ozone.h" namespace ui { // A cursor that is an SkBitmap combined with a gfx::Point hotspot. -class UI_BASE_EXPORT BitmapCursorOzone +class COMPONENT_EXPORT(UI_BASE_CURSOR) BitmapCursorOzone : public base::RefCounted { public: BitmapCursorOzone(const SkBitmap& bitmap, const gfx::Point& hotspot); @@ -45,14 +44,15 @@ class UI_BASE_EXPORT BitmapCursorOzone DISALLOW_COPY_AND_ASSIGN(BitmapCursorOzone); }; -// CursorFactoryOzone implementation for bitmapped cursors. +// CursorFactory implementation for bitmapped cursors. // // This is a base class for platforms where PlatformCursor is an SkBitmap // combined with a gfx::Point for the hotspot. // // Subclasses need only implement SetBitmapCursor() as everything else is // implemented here. -class UI_BASE_EXPORT BitmapCursorFactoryOzone : public CursorFactoryOzone { +class COMPONENT_EXPORT(UI_BASE_CURSOR) BitmapCursorFactoryOzone + : public CursorFactory { public: BitmapCursorFactoryOzone(); ~BitmapCursorFactoryOzone() override; @@ -62,26 +62,17 @@ class UI_BASE_EXPORT BitmapCursorFactoryOzone : public CursorFactoryOzone { PlatformCursor platform_cursor); // CursorFactoryOzone: - PlatformCursor GetDefaultCursor(mojom::CursorType type) override; + base::Optional GetDefaultCursor( + mojom::CursorType type) override; PlatformCursor CreateImageCursor(const SkBitmap& bitmap, - const gfx::Point& hotspot, - float bitmap_dpi) override; + const gfx::Point& hotspot) override; PlatformCursor CreateAnimatedCursor(const std::vector& bitmaps, const gfx::Point& hotspot, - int frame_delay_ms, - float bitmap_dpi) override; + int frame_delay_ms) override; void RefImageCursor(PlatformCursor cursor) override; void UnrefImageCursor(PlatformCursor cursor) override; private: - // Get cached BitmapCursorOzone for a default cursor. - scoped_refptr GetDefaultCursorInternal( - mojom::CursorType type); - - // Default cursors are cached & owned by the factory. - std::map> - default_cursors_; - DISALLOW_COPY_AND_ASSIGN(BitmapCursorFactoryOzone); }; diff --git a/chromium/ui/base/device_form_factor.h b/chromium/ui/base/device_form_factor.h index f87ceca159f..e7c52c28897 100644 --- a/chromium/ui/base/device_form_factor.h +++ b/chromium/ui/base/device_form_factor.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_DEVICE_FORM_FACTOR_H_ #define UI_BASE_DEVICE_FORM_FACTOR_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -17,7 +17,7 @@ enum DeviceFormFactor { // Returns the form factor of current device. For platforms other than Android // and iOS, DEVICE_FORM_FACTOR_DESKTOP is always returned. -UI_BASE_EXPORT DeviceFormFactor GetDeviceFormFactor(); +COMPONENT_EXPORT(UI_BASE) DeviceFormFactor GetDeviceFormFactor(); } // namespace ui diff --git a/chromium/ui/base/dragdrop/cocoa_dnd_util.h b/chromium/ui/base/dragdrop/cocoa_dnd_util.h index 1945c177293..1daf898b21c 100644 --- a/chromium/ui/base/dragdrop/cocoa_dnd_util.h +++ b/chromium/ui/base/dragdrop/cocoa_dnd_util.h @@ -9,8 +9,8 @@ #include +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" class GURL; @@ -20,24 +20,25 @@ namespace ui { // any data associated with this type; it's only used to ensure that Chrome // supports any drag initiated inside of Chrome, whether or not data has been // associated with it. -UI_BASE_EXPORT extern NSString* const kChromeDragDummyPboardType; +COMPONENT_EXPORT(UI_BASE) extern NSString* const kChromeDragDummyPboardType; // Mail.app and TextEdit accept drags that have both HTML and image flavors on // them, but don't process them correctly . Therefore, // if there is an image flavor, don't put the HTML data on as HTML, but rather // put it on as this Chrome-only flavor. External apps won't see HTML but // Chrome will know enough to read it as HTML. -UI_BASE_EXPORT extern NSString* const kChromeDragImageHTMLPboardType; +COMPONENT_EXPORT(UI_BASE) extern NSString* const kChromeDragImageHTMLPboardType; // Populates the |url| and |title| with URL data in |pboard|. There may be more // than one, but we only handle dropping the first. |url| must not be |NULL|; // |title| is an optional parameter. Returns |YES| if URL data was obtained from // the pasteboard, |NO| otherwise. If |convert_filenames| is |YES|, the function // will also attempt to convert filenames in |pboard| to file URLs. -UI_BASE_EXPORT BOOL PopulateURLAndTitleFromPasteboard(GURL* url, - base::string16* title, - NSPasteboard* pboard, - BOOL convert_filenames); +COMPONENT_EXPORT(UI_BASE) +BOOL PopulateURLAndTitleFromPasteboard(GURL* url, + base::string16* title, + NSPasteboard* pboard, + BOOL convert_filenames); } // namespace ui diff --git a/chromium/ui/base/dragdrop/drag_drop_types.h b/chromium/ui/base/dragdrop/drag_drop_types.h index ddb726fe53a..af2fad11112 100644 --- a/chromium/ui/base/dragdrop/drag_drop_types.h +++ b/chromium/ui/base/dragdrop/drag_drop_types.h @@ -7,12 +7,12 @@ #include +#include "base/component_export.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" namespace ui { -class UI_BASE_EXPORT DragDropTypes { +class COMPONENT_EXPORT(UI_BASE) DragDropTypes { public: enum DragOperation { DRAG_NONE = 0, diff --git a/chromium/ui/base/dragdrop/drag_source_win.cc b/chromium/ui/base/dragdrop/drag_source_win.cc index fe201a8d9c1..c27409139ee 100644 --- a/chromium/ui/base/dragdrop/drag_source_win.cc +++ b/chromium/ui/base/dragdrop/drag_source_win.cc @@ -24,7 +24,7 @@ HRESULT DragSourceWin::QueryContinueDrag(BOOL escape_pressed, DWORD key_state) { return DRAGDROP_S_CANCEL; } - if (!(key_state & MK_LBUTTON)) { + if (!(key_state & MK_LBUTTON) && !(key_state & MK_RBUTTON)) { OnDragSourceDrop(); return DRAGDROP_S_DROP; } diff --git a/chromium/ui/base/dragdrop/drag_source_win.h b/chromium/ui/base/dragdrop/drag_source_win.h index 5634d7082c1..466ec9672ad 100644 --- a/chromium/ui/base/dragdrop/drag_source_win.h +++ b/chromium/ui/base/dragdrop/drag_source_win.h @@ -8,9 +8,9 @@ #include #include +#include "base/component_export.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "ui/base/ui_base_export.h" namespace ui { @@ -26,7 +26,8 @@ class DragSourceWin IDropSource> { public: // Factory method to avoid exporting the class and all it derives from. - static UI_BASE_EXPORT Microsoft::WRL::ComPtr Create(); + static COMPONENT_EXPORT( + UI_BASE) Microsoft::WRL::ComPtr Create(); // Use Create() to construct these objects. Direct calls to the constructor // are an error - it is only public because a WRL helper function creates the diff --git a/chromium/ui/base/dragdrop/drop_target_event.h b/chromium/ui/base/dragdrop/drop_target_event.h index 47f1b4e09ae..5a8abf1f40c 100644 --- a/chromium/ui/base/dragdrop/drop_target_event.h +++ b/chromium/ui/base/dragdrop/drop_target_event.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_DRAGDROP_DROP_TARGET_EVENT_H_ #define UI_BASE_DRAGDROP_DROP_TARGET_EVENT_H_ +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/events/event.h" @@ -13,7 +14,7 @@ namespace ui { // Note: This object must not outlive the OSExchangeData used to construct it, // as it stores that by reference. -class UI_BASE_EXPORT DropTargetEvent : public LocatedEvent { +class COMPONENT_EXPORT(UI_BASE) DropTargetEvent : public LocatedEvent { public: DropTargetEvent(const OSExchangeData& data, const gfx::PointF& location, diff --git a/chromium/ui/base/dragdrop/drop_target_win.h b/chromium/ui/base/dragdrop/drop_target_win.h index 6470b34c891..18409b41d36 100644 --- a/chromium/ui/base/dragdrop/drop_target_win.h +++ b/chromium/ui/base/dragdrop/drop_target_win.h @@ -7,9 +7,9 @@ #include +#include "base/component_export.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "ui/base/ui_base_export.h" // Windows interface. struct IDropTargetHelper; @@ -25,7 +25,7 @@ namespace ui { // before the HWND is deleted too. // // This class is meant to be used in a STA and is not multithread-safe. -class UI_BASE_EXPORT DropTargetWin : public IDropTarget { +class COMPONENT_EXPORT(UI_BASE) DropTargetWin : public IDropTarget { public: DropTargetWin(); virtual ~DropTargetWin(); diff --git a/chromium/ui/base/dragdrop/os_exchange_data.cc b/chromium/ui/base/dragdrop/os_exchange_data.cc index 727deb75a01..f8c4f3e8929 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data.cc @@ -99,7 +99,7 @@ bool OSExchangeData::HasAnyFormat( const std::set& format_types) const { if ((formats & STRING) != 0 && HasString()) return true; - if ((formats & URL) != 0 && HasURL(CONVERT_FILENAMES)) + if ((formats & URL) != 0 && HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)) return true; #if defined(OS_WIN) if ((formats & FILE_CONTENTS) != 0 && provider_->HasFileContents()) diff --git a/chromium/ui/base/dragdrop/os_exchange_data.h b/chromium/ui/base/dragdrop/os_exchange_data.h index 58b160be349..bd851a065fc 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data.h +++ b/chromium/ui/base/dragdrop/os_exchange_data.h @@ -18,10 +18,10 @@ #endif #include "base/callback_forward.h" +#include "base/component_export.h" #include "base/files/file_path.h" #include "base/macros.h" #include "ui/base/dragdrop/os_exchange_data_provider.h" -#include "ui/base/ui_base_export.h" class GURL; @@ -48,7 +48,7 @@ struct FileInfo; // TabContentsViewGtk uses a different class to handle drag support that does // not use OSExchangeData. As such, file contents and html support is only // compiled on windows. -class UI_BASE_EXPORT OSExchangeData { +class COMPONENT_EXPORT(UI_BASE) OSExchangeData { public: // Enumeration of the known formats. enum Format { diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider.h b/chromium/ui/base/dragdrop/os_exchange_data_provider.h index 2e45ee878fb..b945ec9180f 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider.h @@ -33,8 +33,7 @@ namespace ui { // Controls whether or not filenames should be converted to file: URLs when // getting a URL. -// TODO(crbug.com/1070138): convert to enum class. -enum FilenameToURLPolicy { +enum class FilenameToURLPolicy { CONVERT_FILENAMES, DO_NOT_CONVERT_FILENAMES, }; diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc deleted file mode 100644 index 7131bc01992..00000000000 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.cc +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/base/dragdrop/os_exchange_data_provider_aura.h" - -#include "base/check.h" -#include "base/memory/ptr_util.h" -#include "base/strings/utf_string_conversions.h" -#include "net/base/filename_util.h" -#include "ui/base/clipboard/clipboard_format_type.h" -#include "ui/base/dragdrop/file_info/file_info.h" - -namespace ui { - -OSExchangeDataProviderAura::OSExchangeDataProviderAura() - : formats_(0) { -} - -OSExchangeDataProviderAura::~OSExchangeDataProviderAura() = default; - -std::unique_ptr OSExchangeDataProviderAura::Clone() - const { - OSExchangeDataProviderAura* ret = new OSExchangeDataProviderAura(); - ret->formats_ = formats_; - ret->string_ = string_; - ret->url_ = url_; - ret->title_ = title_; - ret->filenames_ = filenames_; - ret->pickle_data_ = pickle_data_; - // We skip copying the drag images. - ret->html_ = html_; - ret->base_url_ = base_url_; - - return base::WrapUnique(ret); -} - -void OSExchangeDataProviderAura::MarkOriginatedFromRenderer() { - // TODO(dcheng): Currently unneeded because ChromeOS Aura correctly separates - // URL and filename metadata, and does not implement the DownloadURL protocol. -} - -bool OSExchangeDataProviderAura::DidOriginateFromRenderer() const { - return false; -} - -void OSExchangeDataProviderAura::SetString(const base::string16& data) { - if (HasString()) - return; - - string_ = data; - formats_ |= OSExchangeData::STRING; -} - -void OSExchangeDataProviderAura::SetURL(const GURL& url, - const base::string16& title) { - url_ = url; - title_ = title; - formats_ |= OSExchangeData::URL; - - SetString(base::UTF8ToUTF16(url.spec())); -} - -void OSExchangeDataProviderAura::SetFilename(const base::FilePath& path) { - filenames_.clear(); - filenames_.push_back(FileInfo(path, base::FilePath())); - formats_ |= OSExchangeData::FILE_NAME; -} - -void OSExchangeDataProviderAura::SetFilenames( - const std::vector& filenames) { - filenames_ = filenames; - formats_ |= OSExchangeData::FILE_NAME; -} - -void OSExchangeDataProviderAura::SetPickledData( - const ClipboardFormatType& format, - const base::Pickle& data) { - pickle_data_[format] = data; - formats_ |= OSExchangeData::PICKLED_DATA; -} - -bool OSExchangeDataProviderAura::GetString(base::string16* data) const { - if ((formats_ & OSExchangeData::STRING) == 0) - return false; - *data = string_; - return true; -} - -bool OSExchangeDataProviderAura::GetURLAndTitle(FilenameToURLPolicy policy, - GURL* url, - base::string16* title) const { - if ((formats_ & OSExchangeData::URL) == 0) { - title->clear(); - return GetPlainTextURL(url) || - (policy == CONVERT_FILENAMES && GetFileURL(url)); - } - - if (!url_.is_valid()) - return false; - - *url = url_; - *title = title_; - return true; -} - -bool OSExchangeDataProviderAura::GetFilename(base::FilePath* path) const { - if ((formats_ & OSExchangeData::FILE_NAME) == 0) - return false; - DCHECK(!filenames_.empty()); - *path = filenames_[0].path; - return true; -} - -bool OSExchangeDataProviderAura::GetFilenames( - std::vector* filenames) const { - if ((formats_ & OSExchangeData::FILE_NAME) == 0) - return false; - *filenames = filenames_; - return true; -} - -bool OSExchangeDataProviderAura::GetPickledData( - const ClipboardFormatType& format, - base::Pickle* data) const { - PickleData::const_iterator i = pickle_data_.find(format); - if (i == pickle_data_.end()) - return false; - - *data = i->second; - return true; -} - -bool OSExchangeDataProviderAura::HasString() const { - return (formats_ & OSExchangeData::STRING) != 0; -} - -bool OSExchangeDataProviderAura::HasURL(FilenameToURLPolicy policy) const { - if ((formats_ & OSExchangeData::URL) != 0) { - return true; - } - // No URL, see if we have plain text that can be parsed as a URL. - return GetPlainTextURL(NULL) || - (policy == CONVERT_FILENAMES && GetFileURL(nullptr)); -} - -bool OSExchangeDataProviderAura::HasFile() const { - return (formats_ & OSExchangeData::FILE_NAME) != 0; -} - -bool OSExchangeDataProviderAura::HasCustomFormat( - const ClipboardFormatType& format) const { - return base::Contains(pickle_data_, format); -} - -void OSExchangeDataProviderAura::SetHtml(const base::string16& html, - const GURL& base_url) { - formats_ |= OSExchangeData::HTML; - html_ = html; - base_url_ = base_url; -} - -bool OSExchangeDataProviderAura::GetHtml(base::string16* html, - GURL* base_url) const { - if ((formats_ & OSExchangeData::HTML) == 0) - return false; - *html = html_; - *base_url = base_url_; - return true; -} - -bool OSExchangeDataProviderAura::HasHtml() const { - return ((formats_ & OSExchangeData::HTML) != 0); -} - -void OSExchangeDataProviderAura::SetDragImage( - const gfx::ImageSkia& image, - const gfx::Vector2d& cursor_offset) { - drag_image_ = image; - drag_image_offset_ = cursor_offset; -} - -gfx::ImageSkia OSExchangeDataProviderAura::GetDragImage() const { - return drag_image_; -} - -gfx::Vector2d OSExchangeDataProviderAura::GetDragImageOffset() const { - return drag_image_offset_; -} - -bool OSExchangeDataProviderAura::GetFileURL(GURL* url) const { - base::FilePath file_path; - if (!GetFilename(&file_path)) - return false; - - GURL test_url = net::FilePathToFileURL(file_path); - if (!test_url.is_valid()) - return false; - - if (url) - *url = test_url; - return true; -} - -bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const { - if ((formats_ & OSExchangeData::STRING) == 0) - return false; - - GURL test_url(string_); - if (!test_url.is_valid()) - return false; - - if (url) - *url = test_url; - return true; -} - -} // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h deleted file mode 100644 index c535f08666a..00000000000 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_aura.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURA_H_ -#define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURA_H_ - -#include - -#include "base/files/file_path.h" -#include "base/macros.h" -#include "base/pickle.h" -#include "ui/base/dragdrop/os_exchange_data.h" -#include "ui/gfx/geometry/vector2d.h" -#include "ui/gfx/image/image_skia.h" -#include "url/gurl.h" - -namespace ui { - -class ClipboardFormatType; - -// OSExchangeDataProvider implementation for aura on linux. -class UI_BASE_EXPORT OSExchangeDataProviderAura - : public OSExchangeDataProvider { - public: - OSExchangeDataProviderAura(); - ~OSExchangeDataProviderAura() override; - - // Overridden from OSExchangeDataProvider: - std::unique_ptr Clone() const override; - void MarkOriginatedFromRenderer() override; - bool DidOriginateFromRenderer() const override; - void SetString(const base::string16& data) override; - void SetURL(const GURL& url, const base::string16& title) override; - void SetFilename(const base::FilePath& path) override; - void SetFilenames(const std::vector& filenames) override; - void SetPickledData(const ClipboardFormatType& format, - const base::Pickle& data) override; - bool GetString(base::string16* data) const override; - bool GetURLAndTitle(FilenameToURLPolicy policy, - GURL* url, - base::string16* title) const override; - bool GetFilename(base::FilePath* path) const override; - bool GetFilenames(std::vector* filenames) const override; - bool GetPickledData(const ClipboardFormatType& format, - base::Pickle* data) const override; - bool HasString() const override; - bool HasURL(FilenameToURLPolicy policy) const override; - bool HasFile() const override; - bool HasCustomFormat(const ClipboardFormatType& format) const override; - - void SetHtml(const base::string16& html, const GURL& base_url) override; - bool GetHtml(base::string16* html, GURL* base_url) const override; - bool HasHtml() const override; - void SetDragImage(const gfx::ImageSkia& image, - const gfx::Vector2d& cursor_offset) override; - gfx::ImageSkia GetDragImage() const override; - gfx::Vector2d GetDragImageOffset() const override; - - private: - typedef std::map PickleData; - - // Returns true if |formats_| contains a file format and the file name can be - // parsed as a URL. - bool GetFileURL(GURL* url) const; - - // Returns true if |formats_| contains a string format and the string can be - // parsed as a URL. - bool GetPlainTextURL(GURL* url) const; - - // Actual formats that have been set. See comment above |known_formats_| - // for details. - int formats_; - - // String contents. - base::string16 string_; - - // URL contents. - GURL url_; - base::string16 title_; - - // File name. - std::vector filenames_; - - // PICKLED_DATA contents. - PickleData pickle_data_; - - // Drag image and offset data. - gfx::ImageSkia drag_image_; - gfx::Vector2d drag_image_offset_; - - // For HTML format - base::string16 html_; - GURL base_url_; - - DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderAura); -}; - -} // namespace ui - -#endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_AURA_H_ diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.cc index 52efa7c8e6a..fcf63aac986 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.cc @@ -13,7 +13,7 @@ #if defined(USE_OZONE) #include "ui/base/dragdrop/os_exchange_data_provider_factory_ozone.h" #endif -#include "ui/base/dragdrop/os_exchange_data_provider_aura.h" +#include "ui/base/dragdrop/os_exchange_data_provider_non_backed.h" #elif defined(OS_MACOSX) #include "ui/base/dragdrop/os_exchange_data_provider_builder_mac.h" #elif defined(OS_WIN) @@ -39,7 +39,7 @@ OSExchangeDataProviderFactory::CreateProvider() { return provider; } #endif - return std::make_unique(); + return std::make_unique(); #elif defined(OS_MACOSX) return BuildOSExchangeDataProviderMac(); #elif defined(OS_WIN) diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.h index b3fbd31a564..72ac48751a5 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_factory.h @@ -7,13 +7,13 @@ #include +#include "base/component_export.h" #include "ui/base/dragdrop/os_exchange_data_provider.h" -#include "ui/base/ui_base_export.h" namespace ui { // Builds platform specific OSExchangeDataProviders. -class UI_BASE_EXPORT OSExchangeDataProviderFactory { +class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderFactory { public: // Creates a Provider based on the current platform. static std::unique_ptr CreateProvider(); diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h index 11465f8cc86..8fb6a3ad5c6 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.h @@ -7,6 +7,7 @@ #include +#include "base/component_export.h" #include "base/mac/scoped_nsobject.h" #include "base/macros.h" #include "base/memory/ref_counted.h" @@ -25,7 +26,8 @@ namespace ui { // OSExchangeDataProvider implementation for Mac. -class UI_BASE_EXPORT OSExchangeDataProviderMac : public OSExchangeDataProvider { +class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderMac + : public OSExchangeDataProvider { public: ~OSExchangeDataProviderMac() override; diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm index 4c7cbf41185..b7f144452f3 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_mac.mm @@ -193,7 +193,8 @@ bool OSExchangeDataProviderMac::GetString(base::string16* data) const { // There was no NSString, check for an NSURL. GURL url; base::string16 title; - bool result = GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &url, &title); + bool result = GetURLAndTitle(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, + &url, &title); if (result) *data = base::UTF8ToUTF16(url.spec()); @@ -218,7 +219,8 @@ bool OSExchangeDataProviderMac::GetURLAndTitle(FilenameToURLPolicy policy, // the trailing slashes off of paths and always returns the last path element // as the title whereas no path conversion nor title is wanted. base::FilePath path; - if (policy != DO_NOT_CONVERT_FILENAMES && GetFilename(&path)) { + if (policy != FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES && + GetFilename(&path)) { NSURL* fileUrl = [NSURL fileURLWithPath:base::SysUTF8ToNSString(path.value())]; *url = diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc new file mode 100644 index 00000000000..a4964922b00 --- /dev/null +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.cc @@ -0,0 +1,225 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/base/dragdrop/os_exchange_data_provider_non_backed.h" + +#include + +#include "base/check.h" +#include "base/files/file_path.h" +#include "base/strings/string16.h" +#include "base/strings/utf_string_conversions.h" +#include "net/base/filename_util.h" +#include "ui/base/clipboard/clipboard_format_type.h" +#include "ui/base/dragdrop/file_info/file_info.h" +#include "ui/base/dragdrop/os_exchange_data.h" +#include "url/gurl.h" + +namespace ui { + +OSExchangeDataProviderNonBacked::OSExchangeDataProviderNonBacked() = default; + +OSExchangeDataProviderNonBacked::~OSExchangeDataProviderNonBacked() = default; + +std::unique_ptr OSExchangeDataProviderNonBacked::Clone() + const { + auto clone = std::make_unique(); + + clone->formats_ = formats_; + clone->string_ = string_; + clone->url_ = url_; + clone->title_ = title_; + clone->filenames_ = filenames_; + clone->pickle_data_ = pickle_data_; + // We skip copying the drag images. + clone->html_ = html_; + clone->base_url_ = base_url_; + + return clone; +} + +void OSExchangeDataProviderNonBacked::MarkOriginatedFromRenderer() { + // TODO(dcheng): Currently unneeded because ChromeOS Aura correctly separates + // URL and filename metadata, and does not implement the DownloadURL protocol. +} + +bool OSExchangeDataProviderNonBacked::DidOriginateFromRenderer() const { + return false; +} + +void OSExchangeDataProviderNonBacked::SetString(const base::string16& data) { + if (HasString()) + return; + + string_ = data; + formats_ |= OSExchangeData::STRING; +} + +void OSExchangeDataProviderNonBacked::SetURL(const GURL& url, + const base::string16& title) { + url_ = url; + title_ = title; + formats_ |= OSExchangeData::URL; + + SetString(base::UTF8ToUTF16(url.spec())); +} + +void OSExchangeDataProviderNonBacked::SetFilename(const base::FilePath& path) { + filenames_.clear(); + filenames_.push_back(FileInfo(path, base::FilePath())); + formats_ |= OSExchangeData::FILE_NAME; +} + +void OSExchangeDataProviderNonBacked::SetFilenames( + const std::vector& filenames) { + filenames_ = filenames; + formats_ |= OSExchangeData::FILE_NAME; +} + +void OSExchangeDataProviderNonBacked::SetPickledData( + const ClipboardFormatType& format, + const base::Pickle& data) { + pickle_data_[format] = data; + formats_ |= OSExchangeData::PICKLED_DATA; +} + +bool OSExchangeDataProviderNonBacked::GetString(base::string16* data) const { + if ((formats_ & OSExchangeData::STRING) == 0) + return false; + *data = string_; + return true; +} + +bool OSExchangeDataProviderNonBacked::GetURLAndTitle( + FilenameToURLPolicy policy, + GURL* url, + base::string16* title) const { + if ((formats_ & OSExchangeData::URL) == 0) { + title->clear(); + return GetPlainTextURL(url) || + (policy == FilenameToURLPolicy::CONVERT_FILENAMES && + GetFileURL(url)); + } + + if (!url_.is_valid()) + return false; + + *url = url_; + *title = title_; + return true; +} + +bool OSExchangeDataProviderNonBacked::GetFilename(base::FilePath* path) const { + if ((formats_ & OSExchangeData::FILE_NAME) == 0) + return false; + DCHECK(!filenames_.empty()); + *path = filenames_[0].path; + return true; +} + +bool OSExchangeDataProviderNonBacked::GetFilenames( + std::vector* filenames) const { + if ((formats_ & OSExchangeData::FILE_NAME) == 0) + return false; + *filenames = filenames_; + return true; +} + +bool OSExchangeDataProviderNonBacked::GetPickledData( + const ClipboardFormatType& format, + base::Pickle* data) const { + const auto i = pickle_data_.find(format); + if (i == pickle_data_.end()) + return false; + + *data = i->second; + return true; +} + +bool OSExchangeDataProviderNonBacked::HasString() const { + return (formats_ & OSExchangeData::STRING) != 0; +} + +bool OSExchangeDataProviderNonBacked::HasURL(FilenameToURLPolicy policy) const { + if ((formats_ & OSExchangeData::URL) != 0) { + return true; + } + // No URL, see if we have plain text that can be parsed as a URL. + return GetPlainTextURL(nullptr) || + (policy == FilenameToURLPolicy::CONVERT_FILENAMES && + GetFileURL(nullptr)); +} + +bool OSExchangeDataProviderNonBacked::HasFile() const { + return (formats_ & OSExchangeData::FILE_NAME) != 0; +} + +bool OSExchangeDataProviderNonBacked::HasCustomFormat( + const ClipboardFormatType& format) const { + return base::Contains(pickle_data_, format); +} + +void OSExchangeDataProviderNonBacked::SetHtml(const base::string16& html, + const GURL& base_url) { + formats_ |= OSExchangeData::HTML; + html_ = html; + base_url_ = base_url; +} + +bool OSExchangeDataProviderNonBacked::GetHtml(base::string16* html, + GURL* base_url) const { + if ((formats_ & OSExchangeData::HTML) == 0) + return false; + *html = html_; + *base_url = base_url_; + return true; +} + +bool OSExchangeDataProviderNonBacked::HasHtml() const { + return ((formats_ & OSExchangeData::HTML) != 0); +} + +void OSExchangeDataProviderNonBacked::SetDragImage( + const gfx::ImageSkia& image, + const gfx::Vector2d& cursor_offset) { + drag_image_ = image; + drag_image_offset_ = cursor_offset; +} + +gfx::ImageSkia OSExchangeDataProviderNonBacked::GetDragImage() const { + return drag_image_; +} + +gfx::Vector2d OSExchangeDataProviderNonBacked::GetDragImageOffset() const { + return drag_image_offset_; +} + +bool OSExchangeDataProviderNonBacked::GetFileURL(GURL* url) const { + base::FilePath file_path; + if (!GetFilename(&file_path)) + return false; + + GURL test_url = net::FilePathToFileURL(file_path); + if (!test_url.is_valid()) + return false; + + if (url) + *url = test_url; + return true; +} + +bool OSExchangeDataProviderNonBacked::GetPlainTextURL(GURL* url) const { + if ((formats_ & OSExchangeData::STRING) == 0) + return false; + + GURL test_url(string_); + if (!test_url.is_valid()) + return false; + + if (url) + *url = test_url; + return true; +} + +} // namespace ui diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h new file mode 100644 index 00000000000..6a15a8df69d --- /dev/null +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_non_backed.h @@ -0,0 +1,107 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_ +#define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_ + +#include + +#include "base/component_export.h" +#include "base/pickle.h" +#include "ui/base/dragdrop/file_info/file_info.h" +#include "ui/base/dragdrop/os_exchange_data_provider.h" +#include "ui/gfx/geometry/vector2d.h" +#include "ui/gfx/image/image_skia.h" +#include "url/gurl.h" + +namespace base { +class FilePath; +} // namespace base + +namespace ui { + +class ClipboardFormatType; + +// Simple OSExchangeDataProvider implementation for aura-based ports with no +// actual platform integration. So data managed by this class is exchangeable +// only among Chromium windows and is available only while it is alive. +class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked + : public OSExchangeDataProvider { + public: + OSExchangeDataProviderNonBacked(); + OSExchangeDataProviderNonBacked(const OSExchangeDataProviderNonBacked&) = + delete; + OSExchangeDataProviderNonBacked& operator=( + const OSExchangeDataProviderNonBacked&) = delete; + ~OSExchangeDataProviderNonBacked() override; + + // Overridden from OSExchangeDataProvider: + std::unique_ptr Clone() const override; + void MarkOriginatedFromRenderer() override; + bool DidOriginateFromRenderer() const override; + void SetString(const base::string16& data) override; + void SetURL(const GURL& url, const base::string16& title) override; + void SetFilename(const base::FilePath& path) override; + void SetFilenames(const std::vector& filenames) override; + void SetPickledData(const ClipboardFormatType& format, + const base::Pickle& data) override; + bool GetString(base::string16* data) const override; + bool GetURLAndTitle(FilenameToURLPolicy policy, + GURL* url, + base::string16* title) const override; + bool GetFilename(base::FilePath* path) const override; + bool GetFilenames(std::vector* filenames) const override; + bool GetPickledData(const ClipboardFormatType& format, + base::Pickle* data) const override; + bool HasString() const override; + bool HasURL(FilenameToURLPolicy policy) const override; + bool HasFile() const override; + bool HasCustomFormat(const ClipboardFormatType& format) const override; + + void SetHtml(const base::string16& html, const GURL& base_url) override; + bool GetHtml(base::string16* html, GURL* base_url) const override; + bool HasHtml() const override; + void SetDragImage(const gfx::ImageSkia& image, + const gfx::Vector2d& cursor_offset) override; + gfx::ImageSkia GetDragImage() const override; + gfx::Vector2d GetDragImageOffset() const override; + + private: + // Returns true if |formats_| contains a file format and the file name can be + // parsed as a URL. + bool GetFileURL(GURL* url) const; + + // Returns true if |formats_| contains a string format and the string can be + // parsed as a URL. + bool GetPlainTextURL(GURL* url) const; + + // Actual formats that have been set. + // for details. + int formats_ = 0; + + // String contents. + base::string16 string_; + + // URL contents. + GURL url_; + base::string16 title_; + + // File name. + std::vector filenames_; + + // PICKLED_DATA contents. + std::map pickle_data_; + + // Drag image and offset data. + gfx::ImageSkia drag_image_; + gfx::Vector2d drag_image_offset_; + + // For HTML format + base::string16 html_; + GURL base_url_; +}; + +} // namespace ui + +#endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_ diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc index 9be3da2f9de..b51a0161fdf 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.cc @@ -542,9 +542,9 @@ bool OSExchangeDataProviderWin::GetURLAndTitle(FilenameToURLPolicy policy, GURL* url, base::string16* title) const { base::string16 url_str; - bool success = - ClipboardUtil::GetUrl(source_object_.Get(), url, title, - policy == CONVERT_FILENAMES ? true : false); + bool success = ClipboardUtil::GetUrl( + source_object_.Get(), url, title, + policy == FilenameToURLPolicy::CONVERT_FILENAMES ? true : false); if (success) { DCHECK(url->is_valid()); return true; @@ -658,7 +658,9 @@ bool OSExchangeDataProviderWin::HasString() const { bool OSExchangeDataProviderWin::HasURL(FilenameToURLPolicy policy) const { return (ClipboardUtil::HasUrl(source_object_.Get(), - policy == CONVERT_FILENAMES ? true : false) || + policy == FilenameToURLPolicy::CONVERT_FILENAMES + ? true + : false) || HasPlainTextURL(source_object_.Get())); } diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h index 481e18f4ab2..f160602b2da 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_win.h @@ -23,10 +23,10 @@ #define IDataObjectAsyncCapability IAsyncOperation #endif +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data_provider.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/image/image_skia.h" @@ -115,7 +115,8 @@ class DataObjectImpl : public DownloadFileObserver, bool async_operation_started_; }; -class UI_BASE_EXPORT OSExchangeDataProviderWin : public OSExchangeDataProvider { +class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderWin + : public OSExchangeDataProvider { public: // Returns true if source has plain text that is a valid url. static bool HasPlainTextURL(IDataObject* source); diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc index f336655478b..fdb28d24631 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.cc @@ -11,11 +11,12 @@ #include "ui/base/x/selection_utils.h" #include "ui/events/platform/platform_event_source.h" #include "ui/gfx/x/x11_atom_cache.h" +#include "ui/gfx/x/xproto.h" namespace ui { OSExchangeDataProviderX11::OSExchangeDataProviderX11( - XID x_window, + x11::Window x_window, const SelectionFormatMap& selection) : XOSExchangeDataProvider(x_window, selection) {} @@ -69,8 +70,9 @@ void OSExchangeDataProviderX11::SetFileContents( base::RefCountedString::TakeString(&file_contents_copy))); } -bool OSExchangeDataProviderX11::DispatchXEvent(XEvent* xev) { - if (xev->type == SelectionRequest && xev->xany.window == x_window()) { +bool OSExchangeDataProviderX11::DispatchXEvent(x11::Event* xev) { + auto* selection = xev->As(); + if (selection && selection->owner == x_window()) { selection_owner().OnSelectionRequest(*xev); return true; } diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h index 980b384c3c5..024152eb474 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11.h @@ -5,18 +5,22 @@ #ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_X11_H_ #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_X11_H_ +#include "base/component_export.h" #include "ui/base/x/x11_os_exchange_data_provider.h" #include "ui/events/platform/x11/x11_event_source.h" +#include "ui/gfx/x/event.h" namespace ui { // OSExchangeDataProvider implementation for x11 linux. -class UI_BASE_EXPORT OSExchangeDataProviderX11 : public XOSExchangeDataProvider, - public XEventDispatcher { +class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderX11 + : public XOSExchangeDataProvider, + public XEventDispatcher { public: // |x_window| is the window the cursor is over, and |selection| is the set of // data being offered. - OSExchangeDataProviderX11(XID x_window, const SelectionFormatMap& selection); + OSExchangeDataProviderX11(x11::Window x_window, + const SelectionFormatMap& selection); // Creates a Provider for sending drag information. This creates its own, // hidden X11 window to own send data. @@ -34,7 +38,7 @@ class UI_BASE_EXPORT OSExchangeDataProviderX11 : public XOSExchangeDataProvider, const std::string& file_contents) override; // XEventDispatcher: - bool DispatchXEvent(XEvent* xev) override; + bool DispatchXEvent(x11::Event* xev) override; private: friend class OSExchangeDataProviderX11Test; diff --git a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11_unittest.cc b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11_unittest.cc index 82f9c71aabd..11a7fd89a44 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_provider_x11_unittest.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_provider_x11_unittest.cc @@ -47,8 +47,8 @@ TEST_F(OSExchangeDataProviderX11Test, MozillaURL) { { GURL out_gurl; base::string16 out_str; - EXPECT_TRUE( - provider.GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str)); + EXPECT_TRUE(provider.GetURLAndTitle( + FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str)); EXPECT_EQ(base::ASCIIToUTF16(kGoogleTitle), out_str); EXPECT_EQ(kGoogleURL, out_gurl.spec()); } @@ -58,8 +58,8 @@ TEST_F(OSExchangeDataProviderX11Test, MozillaURL) { { GURL out_gurl; base::string16 out_str; - EXPECT_TRUE( - provider.GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str)); + EXPECT_TRUE(provider.GetURLAndTitle( + FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str)); EXPECT_EQ(base::string16(), out_str); EXPECT_EQ(kGoogleURL, out_gurl.spec()); } @@ -69,24 +69,24 @@ TEST_F(OSExchangeDataProviderX11Test, FilesArentURLs) { AddURLList(kFileURL); EXPECT_TRUE(provider.HasFile()); - EXPECT_TRUE(provider.HasURL(ui::CONVERT_FILENAMES)); - EXPECT_FALSE(provider.HasURL(ui::DO_NOT_CONVERT_FILENAMES)); + EXPECT_TRUE(provider.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); + EXPECT_FALSE(provider.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); } TEST_F(OSExchangeDataProviderX11Test, HTTPURLsArentFiles) { AddURLList(kGoogleURL); EXPECT_FALSE(provider.HasFile()); - EXPECT_TRUE(provider.HasURL(ui::CONVERT_FILENAMES)); - EXPECT_TRUE(provider.HasURL(ui::DO_NOT_CONVERT_FILENAMES)); + EXPECT_TRUE(provider.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); + EXPECT_TRUE(provider.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); } TEST_F(OSExchangeDataProviderX11Test, URIListWithBoth) { AddURLList("file:///home/user/file.txt\nhttp://www.google.com"); EXPECT_TRUE(provider.HasFile()); - EXPECT_TRUE(provider.HasURL(ui::CONVERT_FILENAMES)); - EXPECT_TRUE(provider.HasURL(ui::DO_NOT_CONVERT_FILENAMES)); + EXPECT_TRUE(provider.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); + EXPECT_TRUE(provider.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); // We should only receive the file from GetFilenames(). std::vector filenames; @@ -97,8 +97,8 @@ TEST_F(OSExchangeDataProviderX11Test, URIListWithBoth) { // We should only receive the URL here. GURL out_gurl; base::string16 out_str; - EXPECT_TRUE( - provider.GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str)); + EXPECT_TRUE(provider.GetURLAndTitle( + FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str)); EXPECT_EQ(base::string16(), out_str); EXPECT_EQ(kGoogleURL, out_gurl.spec()); } @@ -108,7 +108,7 @@ TEST_F(OSExchangeDataProviderX11Test, OnlyStringURLIsUnfiltered) { provider.SetString(file_url); EXPECT_TRUE(provider.HasString()); - EXPECT_FALSE(provider.HasURL(ui::DO_NOT_CONVERT_FILENAMES)); + EXPECT_FALSE(provider.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); } TEST_F(OSExchangeDataProviderX11Test, StringAndURIListFilterString) { diff --git a/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc b/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc index 3c000b0f0a7..e57cc2eb849 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_unittest.cc @@ -48,7 +48,8 @@ TEST_F(OSExchangeDataTest, StringDataGetAndSet) { std::string url_spec = "http://www.goats.com/"; GURL url(url_spec); base::string16 title; - EXPECT_FALSE(data2.GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &url, &title)); + EXPECT_FALSE(data2.GetURLAndTitle( + FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, &url, &title)); // No URLs in |data|, so url should be untouched. EXPECT_EQ(url_spec, url.spec()); } @@ -58,9 +59,9 @@ TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { std::string url_spec = "http://www.google.com/"; GURL url(url_spec); base::string16 url_title = base::ASCIIToUTF16("www.google.com"); - EXPECT_FALSE(data.HasURL(DO_NOT_CONVERT_FILENAMES)); + EXPECT_FALSE(data.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); data.SetURL(url, url_title); - EXPECT_TRUE(data.HasURL(DO_NOT_CONVERT_FILENAMES)); + EXPECT_TRUE(data.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); OSExchangeData data2( std::unique_ptr(data.provider().Clone())); @@ -68,9 +69,10 @@ TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { // URL spec and title should match GURL output_url; base::string16 output_title; - EXPECT_TRUE(data2.HasURL(DO_NOT_CONVERT_FILENAMES)); - EXPECT_TRUE(data2.GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &output_url, - &output_title)); + EXPECT_TRUE(data2.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); + EXPECT_TRUE( + data2.GetURLAndTitle(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, + &output_url, &output_title)); EXPECT_EQ(url_spec, output_url.spec()); EXPECT_EQ(url_title, output_title); base::string16 output_string; @@ -96,16 +98,16 @@ TEST_F(OSExchangeDataTest, URLAndString) { GURL output_url; base::string16 output_title; - EXPECT_TRUE(data.GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &output_url, - &output_title)); + EXPECT_TRUE(data.GetURLAndTitle(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, + &output_url, &output_title)); EXPECT_EQ(url_spec, output_url.spec()); EXPECT_EQ(url_title, output_title); } TEST_F(OSExchangeDataTest, TestFileToURLConversion) { OSExchangeData data; - EXPECT_FALSE(data.HasURL(DO_NOT_CONVERT_FILENAMES)); - EXPECT_FALSE(data.HasURL(CONVERT_FILENAMES)); + EXPECT_FALSE(data.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); + EXPECT_FALSE(data.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); EXPECT_FALSE(data.HasFile()); base::FilePath current_directory; @@ -114,21 +116,22 @@ TEST_F(OSExchangeDataTest, TestFileToURLConversion) { data.SetFilename(current_directory); { - EXPECT_FALSE(data.HasURL(DO_NOT_CONVERT_FILENAMES)); + EXPECT_FALSE(data.HasURL(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES)); GURL actual_url; base::string16 actual_title; - EXPECT_FALSE(data.GetURLAndTitle(DO_NOT_CONVERT_FILENAMES, &actual_url, - &actual_title)); + EXPECT_FALSE( + data.GetURLAndTitle(FilenameToURLPolicy::DO_NOT_CONVERT_FILENAMES, + &actual_url, &actual_title)); EXPECT_EQ(GURL(), actual_url); EXPECT_EQ(base::string16(), actual_title); } { - EXPECT_TRUE(data.HasURL(CONVERT_FILENAMES)); + EXPECT_TRUE(data.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); GURL actual_url; base::string16 actual_title; - EXPECT_TRUE( - data.GetURLAndTitle(CONVERT_FILENAMES, &actual_url, &actual_title)); + EXPECT_TRUE(data.GetURLAndTitle(FilenameToURLPolicy::CONVERT_FILENAMES, + &actual_url, &actual_title)); // Some Mac OS versions return the URL in file://localhost form instead // of file:///, so we compare the url's path not its absolute string. EXPECT_EQ(net::FilePathToFileURL(current_directory).path(), diff --git a/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc b/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc index 750fd72ea75..1bc955e3806 100644 --- a/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc +++ b/chromium/ui/base/dragdrop/os_exchange_data_win_unittest.cc @@ -100,10 +100,11 @@ TEST_F(OSExchangeDataWinTest, StringDataWritingViaCOM) { // Construct a new object with the old object so that we can use our access // APIs. OSExchangeData data2(data.provider().Clone()); - EXPECT_TRUE(data2.HasURL(CONVERT_FILENAMES)); + EXPECT_TRUE(data2.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); GURL url_from_data; std::wstring title; - EXPECT_TRUE(data2.GetURLAndTitle(CONVERT_FILENAMES, &url_from_data, &title)); + EXPECT_TRUE(data2.GetURLAndTitle(FilenameToURLPolicy::CONVERT_FILENAMES, + &url_from_data, &title)); GURL reference_url(input); EXPECT_EQ(reference_url.spec(), url_from_data.spec()); } @@ -147,10 +148,11 @@ TEST_F(OSExchangeDataWinTest, RemoveData) { // Construct a new object with the old object so that we can use our access // APIs. OSExchangeData data2(data.provider().Clone()); - EXPECT_TRUE(data2.HasURL(CONVERT_FILENAMES)); + EXPECT_TRUE(data2.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); GURL url_from_data; std::wstring title; - EXPECT_TRUE(data2.GetURLAndTitle(CONVERT_FILENAMES, &url_from_data, &title)); + EXPECT_TRUE(data2.GetURLAndTitle(FilenameToURLPolicy::CONVERT_FILENAMES, + &url_from_data, &title)); EXPECT_EQ(GURL(input2).spec(), url_from_data.spec()); } @@ -853,10 +855,11 @@ TEST_F(OSExchangeDataWinTest, ProvideURLForPlainTextURL) { data.SetString(L"http://google.com"); OSExchangeData data2(data.provider().Clone()); - ASSERT_TRUE(data2.HasURL(CONVERT_FILENAMES)); + ASSERT_TRUE(data2.HasURL(FilenameToURLPolicy::CONVERT_FILENAMES)); GURL read_url; std::wstring title; - EXPECT_TRUE(data2.GetURLAndTitle(CONVERT_FILENAMES, &read_url, &title)); + EXPECT_TRUE(data2.GetURLAndTitle(FilenameToURLPolicy::CONVERT_FILENAMES, + &read_url, &title)); EXPECT_EQ(GURL("http://google.com"), read_url); } diff --git a/chromium/ui/base/emoji/emoji_panel_helper.h b/chromium/ui/base/emoji/emoji_panel_helper.h index 344316b629f..df37ef0162f 100644 --- a/chromium/ui/base/emoji/emoji_panel_helper.h +++ b/chromium/ui/base/emoji/emoji_panel_helper.h @@ -6,22 +6,22 @@ #define UI_BASE_EMOJI_EMOJI_PANEL_HELPER_H_ #include "base/callback.h" +#include "base/component_export.h" #include "base/macros.h" -#include "ui/base/ui_base_export.h" namespace ui { // Returns whether showing the Emoji Panel is supported on this version of // the operating system. -UI_BASE_EXPORT bool IsEmojiPanelSupported(); +COMPONENT_EXPORT(UI_BASE) bool IsEmojiPanelSupported(); // Invokes the commands to show the Emoji Panel. -UI_BASE_EXPORT void ShowEmojiPanel(); +COMPONENT_EXPORT(UI_BASE) void ShowEmojiPanel(); #if defined(OS_CHROMEOS) // Sets a callback to show the emoji panel (ChromeOS only). -UI_BASE_EXPORT void SetShowEmojiKeyboardCallback( - base::RepeatingClosure callback); +COMPONENT_EXPORT(UI_BASE) +void SetShowEmojiKeyboardCallback(base::RepeatingClosure callback); #endif } // namespace ui diff --git a/chromium/ui/base/idle/BUILD.gn b/chromium/ui/base/idle/BUILD.gn index 9120a2df91e..8e76844e5b6 100644 --- a/chromium/ui/base/idle/BUILD.gn +++ b/chromium/ui/base/idle/BUILD.gn @@ -61,7 +61,6 @@ component("idle") { } if (use_x11 && !is_chromeos) { - configs += [ "//build/config/linux:xscrnsaver" ] deps += [ "//ui/gfx/x" ] sources += [ "idle_query_x11.cc", diff --git a/chromium/ui/base/idle/idle_query_x11.cc b/chromium/ui/base/idle/idle_query_x11.cc index ee676686f36..569c57a2d71 100644 --- a/chromium/ui/base/idle/idle_query_x11.cc +++ b/chromium/ui/base/idle/idle_query_x11.cc @@ -4,43 +4,28 @@ #include "ui/base/idle/idle_query_x11.h" +#include "ui/gfx/x/connection.h" +#include "ui/gfx/x/screensaver.h" #include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_types.h" namespace ui { -class IdleData { - public: - IdleData() { - int event_base; - int error_base; - if (XScreenSaverQueryExtension(gfx::GetXDisplay(), &event_base, - &error_base)) { - mit_info.reset(XScreenSaverAllocInfo()); - } - } - - ~IdleData() { - } - - gfx::XScopedPtr mit_info; -}; - -IdleQueryX11::IdleQueryX11() : idle_data_(new IdleData()) {} +IdleQueryX11::IdleQueryX11() : connection_(x11::Connection::Get()) { + // Let the server know the client version before making any requests. + connection_->screensaver().QueryVersion( + {x11::ScreenSaver::major_version, x11::ScreenSaver::minor_version}); +} -IdleQueryX11::~IdleQueryX11() {} +IdleQueryX11::~IdleQueryX11() = default; int IdleQueryX11::IdleTime() { - if (!idle_data_->mit_info) - return 0; - - if (XScreenSaverQueryInfo(gfx::GetXDisplay(), - XRootWindow(gfx::GetXDisplay(), 0), - idle_data_->mit_info.get())) { - return (idle_data_->mit_info->idle) / 1000; - } else { - return 0; + if (auto reply = connection_->screensaver() + .QueryInfo({connection_->default_root()}) + .Sync()) { + return reply->ms_since_user_input / 1000; } + return 0; } } // namespace ui diff --git a/chromium/ui/base/idle/idle_query_x11.h b/chromium/ui/base/idle/idle_query_x11.h index 0857418897e..457aada6a1e 100644 --- a/chromium/ui/base/idle/idle_query_x11.h +++ b/chromium/ui/base/idle/idle_query_x11.h @@ -9,9 +9,11 @@ #include "base/macros.h" -namespace ui { +namespace x11 { +class Connection; +} -class IdleData; +namespace ui { class IdleQueryX11 { public: @@ -21,7 +23,7 @@ class IdleQueryX11 { int IdleTime(); private: - std::unique_ptr idle_data_; + x11::Connection* connection_; DISALLOW_COPY_AND_ASSIGN(IdleQueryX11); }; diff --git a/chromium/ui/base/idle/screensaver_window_finder_x11.cc b/chromium/ui/base/idle/screensaver_window_finder_x11.cc index 74f1a5f6fcd..45342ff5383 100644 --- a/chromium/ui/base/idle/screensaver_window_finder_x11.cc +++ b/chromium/ui/base/idle/screensaver_window_finder_x11.cc @@ -5,26 +5,27 @@ #include "ui/base/idle/screensaver_window_finder_x11.h" #include "ui/base/x/x11_util.h" +#include "ui/gfx/x/connection.h" +#include "ui/gfx/x/screensaver.h" #include "ui/gfx/x/x11.h" #include "ui/gfx/x/x11_atom_cache.h" #include "ui/gfx/x/x11_error_tracker.h" namespace ui { -ScreensaverWindowFinder::ScreensaverWindowFinder() - : exists_(false) { -} +ScreensaverWindowFinder::ScreensaverWindowFinder() : exists_(false) {} bool ScreensaverWindowFinder::ScreensaverWindowExists() { - XScreenSaverInfo info; - XDisplay* display = gfx::GetXDisplay(); - XID root = DefaultRootWindow(display); - static int xss_event_base; - static int xss_error_base; - static bool have_xss = - XScreenSaverQueryExtension(display, &xss_event_base, &xss_error_base); - if (have_xss && XScreenSaverQueryInfo(display, root, &info) && - info.state == ScreenSaverOn) { + auto* connection = x11::Connection::Get(); + + // Let the server know the client version before making any requests. + connection->screensaver().QueryVersion( + {x11::ScreenSaver::major_version, x11::ScreenSaver::minor_version}); + + auto reply = + connection->screensaver().QueryInfo({connection->default_root()}).Sync(); + if (reply && static_cast(reply->state) == + x11::ScreenSaver::State::On) { return true; } @@ -32,9 +33,10 @@ bool ScreensaverWindowFinder::ScreensaverWindowExists() { // info.state == ScreenSaverOff or info.state == ScreenSaverDisabled does not // necessarily mean that a screensaver is not active, so add a special check // for xscreensaver. - XAtom lock_atom = gfx::GetAtom("LOCK"); + x11::Atom lock_atom = gfx::GetAtom("LOCK"); std::vector atom_properties; - if (GetIntArrayProperty(root, "_SCREENSAVER_STATUS", &atom_properties) && + if (GetIntArrayProperty(GetX11RootWindow(), "_SCREENSAVER_STATUS", + &atom_properties) && atom_properties.size() > 0) { if (atom_properties[0] == static_cast(lock_atom)) { return true; @@ -48,14 +50,14 @@ bool ScreensaverWindowFinder::ScreensaverWindowExists() { return finder.exists_ && !err_tracker.FoundNewError(); } -bool ScreensaverWindowFinder::ShouldStopIterating(XID window) { +bool ScreensaverWindowFinder::ShouldStopIterating(x11::Window window) { if (!ui::IsWindowVisible(window) || !IsScreensaverWindow(window)) return false; exists_ = true; return true; } -bool ScreensaverWindowFinder::IsScreensaverWindow(XID window) const { +bool ScreensaverWindowFinder::IsScreensaverWindow(x11::Window window) const { // It should occupy the full screen. if (!ui::IsX11WindowFullScreen(window)) return false; diff --git a/chromium/ui/base/idle/screensaver_window_finder_x11.h b/chromium/ui/base/idle/screensaver_window_finder_x11.h index dad3d209510..a502daa6fbe 100644 --- a/chromium/ui/base/idle/screensaver_window_finder_x11.h +++ b/chromium/ui/base/idle/screensaver_window_finder_x11.h @@ -16,12 +16,12 @@ class ScreensaverWindowFinder : public ui::EnumerateWindowsDelegate { static bool ScreensaverWindowExists(); protected: - bool ShouldStopIterating(XID window) override; + bool ShouldStopIterating(x11::Window window) override; private: ScreensaverWindowFinder(); - bool IsScreensaverWindow(XID window) const; + bool IsScreensaverWindow(x11::Window window) const; bool exists_; diff --git a/chromium/ui/base/ime/BUILD.gn b/chromium/ui/base/ime/BUILD.gn index 2a0670796c0..5ab39cdea54 100644 --- a/chromium/ui/base/ime/BUILD.gn +++ b/chromium/ui/base/ime/BUILD.gn @@ -58,8 +58,6 @@ jumbo_component("ime") { "constants.cc", "constants.h", "ime_assistive_window_handler_interface.h", - "ime_bridge.cc", - "ime_bridge.h", "ime_candidate_window_handler_interface.h", "ime_engine_handler_interface.h", "ime_input_context_handler_interface.h", @@ -81,7 +79,6 @@ jumbo_component("ime") { "text_edit_commands.h", "text_input_client.cc", "text_input_client.h", - "virtual_keyboard_visibility_request.h", ] defines = [ "IS_UI_BASE_IME_IMPL" ] diff --git a/chromium/ui/base/ime/chromeos/BUILD.gn b/chromium/ui/base/ime/chromeos/BUILD.gn index 4baf9294a95..03f91b5ea59 100644 --- a/chromium/ui/base/ime/chromeos/BUILD.gn +++ b/chromium/ui/base/ime/chromeos/BUILD.gn @@ -22,6 +22,8 @@ jumbo_component("chromeos") { "fake_ime_keyboard.h", "fake_input_method_delegate.cc", "fake_input_method_delegate.h", + "ime_bridge.cc", + "ime_bridge.h", "ime_keyboard.cc", "ime_keyboard_impl.cc", "ime_keyboard_impl.h", diff --git a/chromium/ui/base/ime/dummy_input_method.cc b/chromium/ui/base/ime/dummy_input_method.cc index 4e3dff450b2..da32e766c9c 100644 --- a/chromium/ui/base/ime/dummy_input_method.cc +++ b/chromium/ui/base/ime/dummy_input_method.cc @@ -98,9 +98,4 @@ DummyInputMethod::GetInputMethodKeyboardController() { return nullptr; } -const std::vector>& -DummyInputMethod::GetKeyEventsForTesting() { - return key_events_for_testing_; -} - } // namespace ui diff --git a/chromium/ui/base/ime/dummy_input_method.h b/chromium/ui/base/ime/dummy_input_method.h index 9865876b0ad..fba6e76cdb2 100644 --- a/chromium/ui/base/ime/dummy_input_method.h +++ b/chromium/ui/base/ime/dummy_input_method.h @@ -49,11 +49,7 @@ class DummyInputMethod : public InputMethod { void RemoveObserver(InputMethodObserver* observer) override; InputMethodKeyboardController* GetInputMethodKeyboardController() override; - const std::vector>& GetKeyEventsForTesting() - override; - private: - std::vector> key_events_for_testing_; DISALLOW_COPY_AND_ASSIGN(DummyInputMethod); }; diff --git a/chromium/ui/base/ime/dummy_text_input_client.cc b/chromium/ui/base/ime/dummy_text_input_client.cc index 2ed42e851b2..a286b663259 100644 --- a/chromium/ui/base/ime/dummy_text_input_client.cc +++ b/chromium/ui/base/ime/dummy_text_input_client.cc @@ -152,6 +152,14 @@ bool DummyTextInputClient::SetCompositionFromExistingText( } #endif +#if defined(OS_CHROMEOS) +bool DummyTextInputClient::SetAutocorrectRange( + const base::string16& autocorrect_text, + const gfx::Range& range) { + return false; +} +#endif + #if defined(OS_WIN) void DummyTextInputClient::GetActiveTextInputControlLayoutBounds( base::Optional* control_bounds, diff --git a/chromium/ui/base/ime/dummy_text_input_client.h b/chromium/ui/base/ime/dummy_text_input_client.h index e145feda8f6..af8f0ad48fc 100644 --- a/chromium/ui/base/ime/dummy_text_input_client.h +++ b/chromium/ui/base/ime/dummy_text_input_client.h @@ -62,6 +62,12 @@ class DummyTextInputClient : public TextInputClient { const std::vector& ui_ime_text_spans) override; #endif +#if defined(OS_CHROMEOS) + // Set the autocorrect range + bool SetAutocorrectRange(const base::string16& autocorrect_text, + const gfx::Range& range) override; +#endif + #if defined(OS_WIN) void GetActiveTextInputControlLayoutBounds( base::Optional* control_bounds, diff --git a/chromium/ui/base/ime/fuchsia/input_method_fuchsia.cc b/chromium/ui/base/ime/fuchsia/input_method_fuchsia.cc index 2d205c8d182..9959fa3d031 100644 --- a/chromium/ui/base/ime/fuchsia/input_method_fuchsia.cc +++ b/chromium/ui/base/ime/fuchsia/input_method_fuchsia.cc @@ -9,7 +9,7 @@ #include #include -#include "base/fuchsia/default_context.h" +#include "base/fuchsia/process_context.h" #include "ui/base/ime/text_input_client.h" #include "ui/events/base_event_utils.h" #include "ui/events/keycodes/dom/dom_code.h" @@ -22,7 +22,7 @@ InputMethodFuchsia::InputMethodFuchsia(internal::InputMethodDelegate* delegate, : InputMethodBase(delegate), event_converter_(this), ime_client_binding_(this), - ime_service_(base::fuchsia::ComponentContextForCurrentProcess() + ime_service_(base::ComponentContextForProcess() ->svc() ->Connect()), virtual_keyboard_controller_(ime_service_.get()) {} diff --git a/chromium/ui/base/ime/fuchsia/input_method_keyboard_controller_fuchsia.cc b/chromium/ui/base/ime/fuchsia/input_method_keyboard_controller_fuchsia.cc index c284253ad9b..6a6271b471e 100644 --- a/chromium/ui/base/ime/fuchsia/input_method_keyboard_controller_fuchsia.cc +++ b/chromium/ui/base/ime/fuchsia/input_method_keyboard_controller_fuchsia.cc @@ -7,9 +7,11 @@ #include #include +#include "base/check.h" #include "base/fuchsia/default_context.h" #include "base/fuchsia/fuchsia_logging.h" -#include "base/logging.h" +#include "base/fuchsia/process_context.h" +#include "base/notreached.h" namespace ui { @@ -17,7 +19,7 @@ InputMethodKeyboardControllerFuchsia::InputMethodKeyboardControllerFuchsia( fuchsia::ui::input::ImeService* ime_service) : ime_service_(ime_service), ime_visibility_( - base::fuchsia::ComponentContextForCurrentProcess() + base::ComponentContextForProcess() ->svc() ->Connect()) { DCHECK(ime_service_); diff --git a/chromium/ui/base/ime/ime_assistive_window_handler_interface.h b/chromium/ui/base/ime/ime_assistive_window_handler_interface.h index 8807731e9a0..d400f291dff 100644 --- a/chromium/ui/base/ime/ime_assistive_window_handler_interface.h +++ b/chromium/ui/base/ime/ime_assistive_window_handler_interface.h @@ -14,6 +14,13 @@ namespace gfx { class Rect; } // namespace gfx +namespace ui { +namespace ime { +struct AssistiveWindowButton; +struct SuggestionDetails; +} // namespace ime +} // namespace ui + namespace chromeos { struct AssistiveWindowProperties; @@ -27,9 +34,19 @@ class COMPONENT_EXPORT(UI_BASE_IME) IMEAssistiveWindowHandlerInterface { virtual void SetAssistiveWindowProperties( const AssistiveWindowProperties& window) {} - virtual void ShowSuggestion(const base::string16& text, - const size_t confirmed_length, - const bool show_tab) {} + virtual void ShowSuggestion(const ui::ime::SuggestionDetails& details) {} + + virtual void ShowMultipleSuggestions( + const std::vector& suggestions) {} + + // Highlights or unhighlights a given assistive button based on the given + // parameters. + virtual void SetButtonHighlighted( + const ui::ime::AssistiveWindowButton& button, + bool highlighted) {} + + virtual void AcceptSuggestion(const base::string16& suggestion) {} + virtual void HideSuggestion() {} // Called to get the current suggestion text. diff --git a/chromium/ui/base/ime/ime_bridge.cc b/chromium/ui/base/ime/ime_bridge.cc deleted file mode 100644 index 5e44712f9a0..00000000000 --- a/chromium/ui/base/ime/ime_bridge.cc +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/base/ime/ime_bridge.h" - -#include - -#include "base/macros.h" -#include "base/memory/singleton.h" -#include "base/observer_list.h" -#include "build/build_config.h" - -namespace ui { - -static IMEBridge* g_ime_bridge = nullptr; - -// An implementation of IMEBridge. -class IMEBridgeImpl : public IMEBridge { - public: - IMEBridgeImpl() - : current_input_context_(ui::TEXT_INPUT_TYPE_NONE, - ui::TEXT_INPUT_MODE_DEFAULT, - 0, - ui::TextInputClient::FOCUS_REASON_NONE, - false /* should_do_learning */) {} - - ~IMEBridgeImpl() override {} - - // IMEBridge override. - IMEInputContextHandlerInterface* GetInputContextHandler() const override { - return input_context_handler_; - } - - // IMEBridge override. - void SetInputContextHandler( - IMEInputContextHandlerInterface* handler) override { - input_context_handler_ = handler; - for (auto& observer : observers_) - observer.OnInputContextHandlerChanged(); - } - - // IMEBridge override. - void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) override { - engine_handler_ = handler; - } - - // IMEBridge override. - IMEEngineHandlerInterface* GetCurrentEngineHandler() const override { - return engine_handler_; - } - - // IMEBridge override. - void SetCurrentInputContext( - const IMEEngineHandlerInterface::InputContext& input_context) override { - current_input_context_ = input_context; - } - - // IMEBridge override. - const IMEEngineHandlerInterface::InputContext& GetCurrentInputContext() - const override { - return current_input_context_; - } - - // IMEBridge override. - void AddObserver(ui::IMEBridgeObserver* observer) override { - observers_.AddObserver(observer); - } - - // IMEBridge override. - void RemoveObserver(ui::IMEBridgeObserver* observer) override { - observers_.RemoveObserver(observer); - } - - // IMEBridge override. - void MaybeSwitchEngine() override { - for (auto& observer : observers_) - observer.OnRequestSwitchEngine(); - } - -#if defined(OS_CHROMEOS) - // IMEBridge override. - void SetCandidateWindowHandler( - chromeos::IMECandidateWindowHandlerInterface* handler) override { - candidate_window_handler_ = handler; - } - - // IMEBridge override. - chromeos::IMECandidateWindowHandlerInterface* GetCandidateWindowHandler() - const override { - return candidate_window_handler_; - } - - // IMEBridge override. - void SetAssistiveWindowHandler( - chromeos::IMEAssistiveWindowHandlerInterface* handler) override { - assistive_window_handler_ = handler; - } - - // IMEBridge override. - chromeos::IMEAssistiveWindowHandlerInterface* GetAssistiveWindowHandler() - const override { - return assistive_window_handler_; - } -#endif - - private: - IMEInputContextHandlerInterface* input_context_handler_ = nullptr; - IMEEngineHandlerInterface* engine_handler_ = nullptr; - base::ObserverList observers_; - IMEEngineHandlerInterface::InputContext current_input_context_; - -#if defined(OS_CHROMEOS) - chromeos::IMECandidateWindowHandlerInterface* candidate_window_handler_ = - nullptr; - chromeos::IMEAssistiveWindowHandlerInterface* assistive_window_handler_ = - nullptr; -#endif - - DISALLOW_COPY_AND_ASSIGN(IMEBridgeImpl); -}; - -/////////////////////////////////////////////////////////////////////////////// -// IMEBridge -IMEBridge::IMEBridge() {} - -IMEBridge::~IMEBridge() {} - -// static. -void IMEBridge::Initialize() { - if (!g_ime_bridge) - g_ime_bridge = new IMEBridgeImpl(); -} - -// static. -void IMEBridge::Shutdown() { - delete g_ime_bridge; - g_ime_bridge = nullptr; -} - -// static. -IMEBridge* IMEBridge::Get() { - return g_ime_bridge; -} - -} // namespace ui diff --git a/chromium/ui/base/ime/ime_bridge.h b/chromium/ui/base/ime/ime_bridge.h deleted file mode 100644 index 9fade0b1944..00000000000 --- a/chromium/ui/base/ime/ime_bridge.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_IME_IME_BRIDGE_H_ -#define UI_BASE_IME_IME_BRIDGE_H_ - -#include "base/component_export.h" -#include "base/macros.h" -#include "build/build_config.h" -#include "ui/base/ime/ime_bridge_observer.h" -#include "ui/base/ime/ime_engine_handler_interface.h" -#include "ui/base/ime/ime_input_context_handler_interface.h" - -#if defined(OS_CHROMEOS) -#include "ui/base/ime/ime_assistive_window_handler_interface.h" -#include "ui/base/ime/ime_candidate_window_handler_interface.h" - -namespace chromeos { -class IMECandidateWindowHandlerInterface; -class IMEAssistiveWindowHandlerInterface; -} -#endif - -namespace ui { - -// IMEBridge provides access of each IME related handler. This class -// is used for IME implementation. -class COMPONENT_EXPORT(UI_BASE_IME) IMEBridge { - public: - virtual ~IMEBridge(); - - // Allocates the global instance. Must be called before any calls to Get(). - static void Initialize(); - - // Releases the global instance. - static void Shutdown(); - - // Returns IMEBridge global instance. Initialize() must be called first. - static IMEBridge* Get(); - - // Returns current InputContextHandler. This function returns NULL if input - // context is not ready to use. - virtual IMEInputContextHandlerInterface* GetInputContextHandler() const = 0; - - // Updates current InputContextHandler. If there is no active input context, - // pass NULL for |handler|. Caller must release |handler|. - virtual void SetInputContextHandler( - IMEInputContextHandlerInterface* handler) = 0; - - // Updates current EngineHandler. If there is no active engine service, pass - // NULL for |handler|. Caller must release |handler|. - virtual void SetCurrentEngineHandler(IMEEngineHandlerInterface* handler) = 0; - - // Returns current EngineHandler. This function returns NULL if current engine - // is not ready to use. - virtual IMEEngineHandlerInterface* GetCurrentEngineHandler() const = 0; - - // Updates the current input context. - // This is called from InputMethodChromeOS. - virtual void SetCurrentInputContext( - const IMEEngineHandlerInterface::InputContext& input_context) = 0; - - // Returns the current input context. - // This is called from InputMethodEngine. - virtual const IMEEngineHandlerInterface::InputContext& - GetCurrentInputContext() const = 0; - - // Add or remove observers of events such as switching engines, etc. - virtual void AddObserver(ui::IMEBridgeObserver* observer) = 0; - virtual void RemoveObserver(ui::IMEBridgeObserver* observer) = 0; - - // Switches the engine handler upon top level window focus change. - virtual void MaybeSwitchEngine() = 0; - -#if defined(OS_CHROMEOS) - // Returns current CandidateWindowHandler. This function returns NULL if - // current candidate window is not ready to use. - virtual chromeos::IMECandidateWindowHandlerInterface* - GetCandidateWindowHandler() const = 0; - - // Updates current CandidatWindowHandler. If there is no active candidate - // window service, pass NULL for |handler|. Caller must release |handler|. - virtual void SetCandidateWindowHandler( - chromeos::IMECandidateWindowHandlerInterface* handler) = 0; - - virtual chromeos::IMEAssistiveWindowHandlerInterface* - GetAssistiveWindowHandler() const = 0; - virtual void SetAssistiveWindowHandler( - chromeos::IMEAssistiveWindowHandlerInterface* handler) = 0; -#endif - - protected: - IMEBridge(); - - private: - DISALLOW_COPY_AND_ASSIGN(IMEBridge); -}; - -} // namespace ui - -#endif // UI_BASE_IME_IME_BRIDGE_H_ diff --git a/chromium/ui/base/ime/ime_engine_handler_interface.h b/chromium/ui/base/ime/ime_engine_handler_interface.h index 4eb49c6ecf0..4895587e81c 100644 --- a/chromium/ui/base/ime/ime_engine_handler_interface.h +++ b/chromium/ui/base/ime/ime_engine_handler_interface.h @@ -24,8 +24,15 @@ class Rect; namespace ui { +class InputMethodKeyboardController; class KeyEvent; +#if defined(OS_CHROMEOS) +namespace ime { +struct AssistiveWindowButton; +} // namespace ime +#endif // defined(OS_CHROMEOS) + // A interface to handle the engine handler method call. class COMPONENT_EXPORT(UI_BASE_IME) IMEEngineHandlerInterface { public: @@ -114,6 +121,10 @@ class COMPONENT_EXPORT(UI_BASE_IME) IMEEngineHandlerInterface { // Called when the composition bounds changed. virtual void SetCompositionBounds(const std::vector& bounds) = 0; + // Gets the implementation of the keyboard controller. + virtual ui::InputMethodKeyboardController* GetInputMethodKeyboardController() + const = 0; + #if defined(OS_CHROMEOS) // Called when a property is activated or changed. @@ -123,6 +134,10 @@ class COMPONENT_EXPORT(UI_BASE_IME) IMEEngineHandlerInterface { // based candidate index in lookup table. virtual void CandidateClicked(uint32_t index) = 0; + // Called when assistive window is clicked. + virtual void AssistiveWindowButtonClicked( + const ui::ime::AssistiveWindowButton& button) {} + // Sets the mirroring/casting enable states. virtual void SetMirroringEnabled(bool mirroring_enabled) = 0; virtual void SetCastingEnabled(bool casting_enabled) = 0; diff --git a/chromium/ui/base/ime/ime_input_context_handler_interface.h b/chromium/ui/base/ime/ime_input_context_handler_interface.h index 5387c7b7b0e..46fd1fef8ea 100644 --- a/chromium/ui/base/ime/ime_input_context_handler_interface.h +++ b/chromium/ui/base/ime/ime_input_context_handler_interface.h @@ -33,6 +33,11 @@ class COMPONENT_EXPORT(UI_BASE_IME) IMEInputContextHandlerInterface { uint32_t after, const std::vector& text_spans) = 0; + // Set the autocorrect range with text. + virtual bool SetAutocorrectRange(const base::string16& autocorrect_text, + uint32_t start, + uint32_t end) = 0; + // Called when the engine changes the selection range. // Returns true if the operation was successful. virtual bool SetSelectionRange(uint32_t start, uint32_t end) = 0; diff --git a/chromium/ui/base/ime/ime_text_span.h b/chromium/ui/base/ime/ime_text_span.h index c76734e2e4f..62bdfb8cbac 100644 --- a/chromium/ui/base/ime/ime_text_span.h +++ b/chromium/ui/base/ime/ime_text_span.h @@ -15,9 +15,6 @@ namespace ui { -// Intentionally keep sync with blink::WebImeTextSpan defined in: -// third_party/WebKit/public/web/WebImeTextSpan.h - struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) ImeTextSpan { enum class Type { // Creates a composition marker. @@ -29,6 +26,8 @@ struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) ImeTextSpan { // replacement, and will be ignored if added to an element with spell // checking disabled. kMisspellingSuggestion, + // Creates an autocorrect marker that isn't cleared by itself. + kAutocorrect, }; enum class Thickness { @@ -72,6 +71,7 @@ struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) ImeTextSpan { rhs.suggestion_highlight_color) && (this->remove_on_finish_composing == rhs.remove_on_finish_composing) && + (this->interim_char_selection == rhs.interim_char_selection) && (this->suggestions == rhs.suggestions); } @@ -87,6 +87,7 @@ struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) ImeTextSpan { SkColor background_color; SkColor suggestion_highlight_color; bool remove_on_finish_composing = false; + bool interim_char_selection = false; std::vector suggestions; }; diff --git a/chromium/ui/base/ime/init/BUILD.gn b/chromium/ui/base/ime/init/BUILD.gn index 0aad80f4551..26e7a60f901 100644 --- a/chromium/ui/base/ime/init/BUILD.gn +++ b/chromium/ui/base/ime/init/BUILD.gn @@ -31,6 +31,9 @@ jumbo_component("init") { if (is_mac) { deps += [ "//ui/base/ime/mac" ] } + if (is_chromeos) { + deps += [ "//ui/base/ime/chromeos" ] + } if (is_linux && !is_chromeos) { deps += [ "//ui/base/ime/linux" ] } diff --git a/chromium/ui/base/ime/init/input_method_factory.cc b/chromium/ui/base/ime/init/input_method_factory.cc index 5e98636a36c..d923c6b2331 100644 --- a/chromium/ui/base/ime/init/input_method_factory.cc +++ b/chromium/ui/base/ime/init/input_method_factory.cc @@ -5,6 +5,7 @@ #include "ui/base/ime/init/input_method_factory.h" #include "base/command_line.h" +#include "base/logging.h" #include "base/memory/ptr_util.h" #include "base/win/windows_version.h" #include "build/build_config.h" @@ -17,10 +18,15 @@ #include "ui/base/ime/win/input_method_win_tsf.h" #elif defined(OS_MACOSX) #include "ui/base/ime/mac/input_method_mac.h" -#elif defined(USE_X11) -#include "ui/base/ime/linux/input_method_auralinux.h" -#elif defined(USE_OZONE) +#elif defined(USE_X11) || defined(USE_OZONE) +#if defined(USE_X11) +// TODO(crbug.com/1085700): Remove nogncheck when we can build both Ozone +// Wayland and X11 on Linux codesearch-gen bots. +#include "ui/base/ime/linux/input_method_auralinux.h" // nogncheck +#endif // defined(USE_X11) +#if defined(USE_OZONE) #include "ui/ozone/public/ozone_platform.h" +#endif // defined(USE_OZONE) #else #include "ui/base/ime/input_method_minimal.h" #endif @@ -63,10 +69,18 @@ std::unique_ptr CreateInputMethod( return std::make_unique(delegate, widget); #elif defined(OS_MACOSX) return std::make_unique(delegate); -#elif defined(USE_X11) - return std::make_unique(delegate); -#elif defined(USE_OZONE) - return ui::OzonePlatform::GetInstance()->CreateInputMethod(delegate, widget); +#elif defined(USE_X11) || defined(USE_OZONE) +#if defined(USE_OZONE) + if (features::IsUsingOzonePlatform()) { + return ui::OzonePlatform::GetInstance()->CreateInputMethod(delegate, + widget); + } +#endif // defined(USE_OZONE) +#if defined(USE_X11) + return std::make_unique(delegate); +#endif // defined(USE_X11) + NOTREACHED(); + return nullptr; #else return std::make_unique(delegate); #endif diff --git a/chromium/ui/base/ime/init/input_method_initializer.cc b/chromium/ui/base/ime/init/input_method_initializer.cc index 1a453109dbc..1bfc48a8005 100644 --- a/chromium/ui/base/ime/init/input_method_initializer.cc +++ b/chromium/ui/base/ime/init/input_method_initializer.cc @@ -9,10 +9,12 @@ #include "build/build_config.h" #if defined(OS_CHROMEOS) -#include "ui/base/ime/ime_bridge.h" +#include "ui/base/ime/chromeos/ime_bridge.h" #elif defined(USE_AURA) && defined(OS_LINUX) #include "base/check.h" -#include "ui/base/ime/linux/fake_input_method_context_factory.h" +// TODO(crbug.com/1085700): Remove nogncheck when we can build both Ozone +// Wayland and X11 on Linux codesearch-gen bots. +#include "ui/base/ime/linux/fake_input_method_context_factory.h" // nogncheck #elif defined(OS_WIN) #include "ui/base/ime/init/input_method_factory.h" #include "ui/base/ime/win/tsf_bridge.h" diff --git a/chromium/ui/base/ime/input_method.h b/chromium/ui/base/ime/input_method.h index b400ece46ac..9ead7fa666e 100644 --- a/chromium/ui/base/ime/input_method.h +++ b/chromium/ui/base/ime/input_method.h @@ -18,10 +18,6 @@ #include "ui/events/platform_event.h" #include "ui/gfx/geometry/rect.h" -namespace extensions { -class InputImeApiTest; -} // namespace extensions - namespace ui { namespace internal { @@ -57,8 +53,6 @@ class TextInputClient; // ui::InputMethod and owns it. class InputMethod { public: - InputMethod() : track_key_events_for_testing_(false) {} - #if defined(OS_WIN) typedef LRESULT NativeEventResult; #else @@ -174,16 +168,6 @@ class InputMethod { // Return the keyboard controller; used only on Windows. virtual InputMethodKeyboardController* GetInputMethodKeyboardController() = 0; - - protected: - friend class extensions::InputImeApiTest; - - // Gets the tracked key events of using input.ime.sendKeyEvents API. - virtual const std::vector>& - GetKeyEventsForTesting() = 0; - - // Whether the key events will be tracked. Only used for testing. - bool track_key_events_for_testing_; }; } // namespace ui diff --git a/chromium/ui/base/ime/input_method_base.cc b/chromium/ui/base/ime/input_method_base.cc index 6051072ddb7..b5f26b6bf9d 100644 --- a/chromium/ui/base/ime/input_method_base.cc +++ b/chromium/ui/base/ime/input_method_base.cc @@ -9,7 +9,6 @@ #include "base/check.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" -#include "ui/base/ime/ime_bridge.h" #include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/input_method_keyboard_controller_stub.h" #include "ui/base/ime/input_method_observer.h" @@ -18,11 +17,6 @@ namespace ui { -ui::IMEEngineHandlerInterface* InputMethodBase::GetEngine() { - auto* bridge = ui::IMEBridge::Get(); - return bridge ? bridge->GetCurrentEngineHandler() : nullptr; -} - InputMethodBase::InputMethodBase(internal::InputMethodDelegate* delegate) : InputMethodBase(delegate, nullptr) {} @@ -35,9 +29,6 @@ InputMethodBase::InputMethodBase( InputMethodBase::~InputMethodBase() { for (InputMethodObserver& observer : observer_list_) observer.OnInputMethodDestroyed(this); - if (ui::IMEBridge::Get() && - ui::IMEBridge::Get()->GetInputContextHandler() == this) - ui::IMEBridge::Get()->SetInputContextHandler(nullptr); } void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { @@ -45,17 +36,9 @@ void InputMethodBase::SetDelegate(internal::InputMethodDelegate* delegate) { } void InputMethodBase::OnFocus() { - ui::IMEBridge* bridge = ui::IMEBridge::Get(); - if (bridge) { - bridge->SetInputContextHandler(this); - bridge->MaybeSwitchEngine(); - } } void InputMethodBase::OnBlur() { - if (ui::IMEBridge::Get() && - ui::IMEBridge::Get()->GetInputContextHandler() == this) - ui::IMEBridge::Get()->SetInputContextHandler(nullptr); } #if defined(OS_WIN) @@ -251,6 +234,13 @@ bool InputMethodBase::SetCompositionRange( return false; } +bool InputMethodBase::SetAutocorrectRange( + const base::string16& autocorrect_text, + uint32_t start, + uint32_t end) { + return false; +} + bool InputMethodBase::SetSelectionRange(uint32_t start, uint32_t end) { return false; } @@ -275,9 +265,6 @@ SurroundingTextInfo InputMethodBase::GetSurroundingTextInfo() { } void InputMethodBase::SendKeyEvent(KeyEvent* event) { - if (track_key_events_for_testing_) { - key_events_for_testing_.push_back(std::make_unique(*event)); - } ui::EventDispatchDetails details = DispatchKeyEvent(event); DCHECK(!details.dispatcher_destroyed); } @@ -298,9 +285,4 @@ bool InputMethodBase::HasCompositionText() { return client && client->HasCompositionText(); } -const std::vector>& -InputMethodBase::GetKeyEventsForTesting() { - return key_events_for_testing_; -} - } // namespace ui diff --git a/chromium/ui/base/ime/input_method_base.h b/chromium/ui/base/ime/input_method_base.h index 7d182e01975..e87cdcab71e 100644 --- a/chromium/ui/base/ime/input_method_base.h +++ b/chromium/ui/base/ime/input_method_base.h @@ -92,6 +92,9 @@ class COMPONENT_EXPORT(UI_BASE_IME) InputMethodBase uint32_t before, uint32_t after, const std::vector& text_spans) override; + bool SetAutocorrectRange(const base::string16& autocorrect_text, + uint32_t start, + uint32_t end) override; bool SetSelectionRange(uint32_t start, uint32_t end) override; #endif @@ -134,23 +137,15 @@ class COMPONENT_EXPORT(UI_BASE_IME) InputMethodBase internal::InputMethodDelegate* delegate() const { return delegate_; } - static IMEEngineHandlerInterface* GetEngine(); - private: internal::InputMethodDelegate* delegate_; - // InputMethod: - const std::vector>& GetKeyEventsForTesting() - override; - void SetFocusedTextInputClientInternal(TextInputClient* client); TextInputClient* text_input_client_ = nullptr; base::ObserverList::Unchecked observer_list_; - std::vector> key_events_for_testing_; - // Screen bounds of a on-screen keyboard. gfx::Rect keyboard_bounds_; diff --git a/chromium/ui/base/ime/linux/BUILD.gn b/chromium/ui/base/ime/linux/BUILD.gn index 01c9b24e6a7..dbef616118c 100644 --- a/chromium/ui/base/ime/linux/BUILD.gn +++ b/chromium/ui/base/ime/linux/BUILD.gn @@ -5,7 +5,14 @@ import("//build/config/jumbo.gni") import("//build/config/linux/pangocairo/pangocairo.gni") -assert(is_linux && !is_chromeos) +# Allows base/ime/linux to be built if it's just for making kythe annotations. +# This is used to generate cross references in codesearch. References are +# generated by building the ozone wayland backend on ChromiumOS, which +# normally we would not want to compile base/ime/linux for. We can't build +# both ozone and x11 on Linux yet, but when we can we should remove this. +# TODO(crbug.com/1085700): Remove || enable_kythe_annotations here. +import("//build/toolchain/kythe.gni") +assert((is_linux && !is_chromeos) || enable_kythe_annotations) jumbo_component("linux") { output_name = "ui_base_ime_linux" diff --git a/chromium/ui/base/ime/linux/input_method_auralinux.cc b/chromium/ui/base/ime/linux/input_method_auralinux.cc index 3f3663c3a51..de49a5b15f1 100644 --- a/chromium/ui/base/ime/linux/input_method_auralinux.cc +++ b/chromium/ui/base/ime/linux/input_method_auralinux.cc @@ -8,8 +8,6 @@ #include "base/bind.h" #include "base/environment.h" #include "ui/base/ime/constants.h" -#include "ui/base/ime/ime_bridge.h" -#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/linux/linux_input_method_context_factory.h" #include "ui/base/ime/text_input_client.h" #include "ui/events/event.h" @@ -88,42 +86,9 @@ ui::EventDispatchDetails InputMethodAuraLinux::DispatchKeyEvent( } } - // If there's an active IME extension is listening to the key event, and the - // current text input client is not password input client, the key event - // should be dispatched to the extension engine in the two conditions: - // 1) |filtered| == false: the ET_KEY_PRESSED event of non-character key, - // or the ET_KEY_RELEASED event of all key. - // 2) |filtered| == true && NeedInsertChar(): the ET_KEY_PRESSED event of - // character key. - if (text_input_type_ != TEXT_INPUT_TYPE_PASSWORD && GetEngine() && - (!filtered || NeedInsertChar())) { - ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback = - base::BindOnce(&InputMethodAuraLinux::ProcessKeyEventByEngineDone, - weak_ptr_factory_.GetWeakPtr(), - base::Owned(new ui::KeyEvent(*event)), filtered, - composition_changed_, - base::Owned(new ui::CompositionText(composition_)), - base::Owned(new base::string16(result_text_))); - GetEngine()->ProcessKeyEvent(*event, std::move(callback)); - return ui::EventDispatchDetails(); - } - return ProcessKeyEventDone(event, filtered, false); } -void InputMethodAuraLinux::ProcessKeyEventByEngineDone( - ui::KeyEvent* event, - bool filtered, - bool composition_changed, - ui::CompositionText* composition, - base::string16* result_text, - bool is_handled) { - composition_changed_ = composition_changed; - composition_ = *composition; - result_text_ = *result_text; - ignore_result(ProcessKeyEventDone(event, filtered, is_handled)); -} - ui::EventDispatchDetails InputMethodAuraLinux::ProcessKeyEventDone( ui::KeyEvent* event, bool filtered, @@ -248,22 +213,6 @@ void InputMethodAuraLinux::UpdateContextFocusState() { context_simple_->Focus(); else context_simple_->Blur(); - - if (!ui::IMEBridge::Get()) // IMEBridge could be null for tests. - return; - - ui::IMEEngineHandlerInterface::InputContext context( - GetTextInputType(), GetTextInputMode(), GetTextInputFlags(), - ui::TextInputClient::FOCUS_REASON_OTHER, GetClientShouldDoLearning()); - ui::IMEBridge::Get()->SetCurrentInputContext(context); - - ui::IMEEngineHandlerInterface* engine = GetEngine(); - if (engine) { - if (old_text_input_type != TEXT_INPUT_TYPE_NONE) - engine->FocusOut(); - if (text_input_type_ != TEXT_INPUT_TYPE_NONE) - engine->FocusIn(context); - } } void InputMethodAuraLinux::OnTextInputTypeChanged( @@ -286,19 +235,12 @@ void InputMethodAuraLinux::OnCaretBoundsChanged(const TextInputClient* client) { client->GetEditableSelectionRange(&selection_range)) { context_->SetSurroundingText(text, selection_range); } - - if (!IsTextInputTypeNone() && text_input_type_ != TEXT_INPUT_TYPE_PASSWORD && - GetEngine()) - GetEngine()->SetCompositionBounds(GetCompositionBounds(client)); } void InputMethodAuraLinux::CancelComposition(const TextInputClient* client) { if (!IsTextInputClientFocused(client)) return; - if (GetEngine()) - GetEngine()->Reset(); - ResetContext(); } @@ -457,8 +399,6 @@ void InputMethodAuraLinux::ConfirmCompositionText(bool reset_engine, NOTIMPLEMENTED_LOG_ONCE(); } InputMethodBase::ConfirmCompositionText(reset_engine, keep_selection); - if (reset_engine && GetEngine()) - GetEngine()->Reset(); ResetContext(); } diff --git a/chromium/ui/base/ime/linux/input_method_auralinux.h b/chromium/ui/base/ime/linux/input_method_auralinux.h index 294979dec2d..e560171df5b 100644 --- a/chromium/ui/base/ime/linux/input_method_auralinux.h +++ b/chromium/ui/base/ime/linux/input_method_auralinux.h @@ -65,18 +65,6 @@ class COMPONENT_EXPORT(UI_BASE_IME_LINUX) InputMethodAuraLinux bool is_handled) WARN_UNUSED_RESULT; - // Callback function for IMEEngineHandlerInterface::ProcessKeyEvent(). - // It recovers the context when the event is being passed to the extension and - // call ProcessKeyEventDone() for the following processing. This is necessary - // as this method is async. The environment may be changed by other generated - // key events by the time the callback is run. - void ProcessKeyEventByEngineDone(ui::KeyEvent* event, - bool filtered, - bool composition_changed, - ui::CompositionText* composition, - base::string16* result_text, - bool is_handled); - std::unique_ptr context_; std::unique_ptr context_simple_; diff --git a/chromium/ui/base/ime/linux/input_method_auralinux_unittest.cc b/chromium/ui/base/ime/linux/input_method_auralinux_unittest.cc index 02819b93d51..c7d29003977 100644 --- a/chromium/ui/base/ime/linux/input_method_auralinux_unittest.cc +++ b/chromium/ui/base/ime/linux/input_method_auralinux_unittest.cc @@ -271,19 +271,19 @@ class TextInputClientForTesting : public DummyTextInputClient { class InputMethodAuraLinuxTest : public testing::Test { protected: InputMethodAuraLinuxTest() - : factory_(NULL), - input_method_auralinux_(NULL), - delegate_(NULL), - context_(NULL), - context_simple_(NULL) { + : factory_(nullptr), + input_method_auralinux_(nullptr), + delegate_(nullptr), + context_(nullptr), + context_simple_(nullptr) { factory_ = new LinuxInputMethodContextFactoryForTesting(); LinuxInputMethodContextFactory::SetInstance(factory_); test_result_ = TestResult::GetInstance(); } ~InputMethodAuraLinuxTest() override { delete factory_; - factory_ = NULL; - test_result_ = NULL; + factory_ = nullptr; + test_result_ = nullptr; } void SetUp() override { @@ -303,13 +303,13 @@ class InputMethodAuraLinuxTest : public testing::Test { context_simple_->SetSyncMode(false); context_simple_->SetEatKey(false); - context_ = NULL; - context_simple_ = NULL; + context_ = nullptr; + context_simple_ = nullptr; delete input_method_auralinux_; - input_method_auralinux_ = NULL; + input_method_auralinux_ = nullptr; delete delegate_; - delegate_ = NULL; + delegate_ = nullptr; } LinuxInputMethodContextFactoryForTesting* factory_; diff --git a/chromium/ui/base/ime/mock_ime_input_context_handler.cc b/chromium/ui/base/ime/mock_ime_input_context_handler.cc index f6d7cf6decb..f2ba25fbeb6 100644 --- a/chromium/ui/base/ime/mock_ime_input_context_handler.cc +++ b/chromium/ui/base/ime/mock_ime_input_context_handler.cc @@ -5,6 +5,7 @@ #include "ui/base/ime/mock_ime_input_context_handler.h" #include "base/logging.h" +#include "base/notreached.h" #include "base/strings/utf_string_conversions.h" #include "ui/base/ime/composition_text.h" #include "ui/base/ime/input_method.h" @@ -16,8 +17,7 @@ MockIMEInputContextHandler::MockIMEInputContextHandler() : commit_text_call_count_(0), set_selection_range_call_count_(0), update_preedit_text_call_count_(0), - delete_surrounding_text_call_count_(0), - last_sent_key_event_(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, 0) {} + delete_surrounding_text_call_count_(0) {} MockIMEInputContextHandler::~MockIMEInputContextHandler() {} @@ -47,6 +47,14 @@ bool MockIMEInputContextHandler::SetCompositionRange( return true; } +bool MockIMEInputContextHandler::SetAutocorrectRange( + const base::string16& autocorrect_text, + uint32_t start, + uint32_t end) { + // TODO(crbug.com/1091088): Implement function. + return false; +} + bool MockIMEInputContextHandler::SetSelectionRange(uint32_t start, uint32_t end) { ++set_selection_range_call_count_; @@ -72,11 +80,11 @@ void MockIMEInputContextHandler::Reset() { update_preedit_text_call_count_ = 0; delete_surrounding_text_call_count_ = 0; last_commit_text_.clear(); - last_sent_key_event_ = ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, 0); + sent_key_events_.clear(); } void MockIMEInputContextHandler::SendKeyEvent(KeyEvent* event) { - last_sent_key_event_ = *event; + sent_key_events_.emplace_back(*event); } InputMethod* MockIMEInputContextHandler::GetInputMethod() { diff --git a/chromium/ui/base/ime/mock_ime_input_context_handler.h b/chromium/ui/base/ime/mock_ime_input_context_handler.h index e13c67f0b9d..6890e6b538a 100644 --- a/chromium/ui/base/ime/mock_ime_input_context_handler.h +++ b/chromium/ui/base/ime/mock_ime_input_context_handler.h @@ -44,6 +44,10 @@ class COMPONENT_EXPORT(UI_BASE_IME) MockIMEInputContextHandler uint32_t after, const std::vector& text_spans) override; + bool SetAutocorrectRange(const base::string16& autocorrect_text, + uint32_t start, + uint32_t end) override; + bool SetSelectionRange(uint32_t start, uint32_t end) override; #endif @@ -66,6 +70,8 @@ class COMPONENT_EXPORT(UI_BASE_IME) MockIMEInputContextHandler return delete_surrounding_text_call_count_; } + int send_key_event_call_count() const { return sent_key_events_.size(); } + const std::string& last_commit_text() const { return last_commit_text_; } const UpdateCompositionTextArg& last_update_composition_arg() const { @@ -76,8 +82,8 @@ class COMPONENT_EXPORT(UI_BASE_IME) MockIMEInputContextHandler return last_delete_surrounding_text_arg_; } - const ui::KeyEvent& last_sent_key_event() const { - return last_sent_key_event_; + const std::vector& sent_key_events() const { + return sent_key_events_; } // Resets all call count. @@ -89,7 +95,7 @@ class COMPONENT_EXPORT(UI_BASE_IME) MockIMEInputContextHandler int update_preedit_text_call_count_; int delete_surrounding_text_call_count_; std::string last_commit_text_; - ui::KeyEvent last_sent_key_event_; + std::vector sent_key_events_; UpdateCompositionTextArg last_update_composition_arg_; DeleteSurroundingTextArg last_delete_surrounding_text_arg_; }; diff --git a/chromium/ui/base/ime/mock_input_method.cc b/chromium/ui/base/ime/mock_input_method.cc index 17555ca526f..5cd43dd5165 100644 --- a/chromium/ui/base/ime/mock_input_method.cc +++ b/chromium/ui/base/ime/mock_input_method.cc @@ -13,8 +13,7 @@ namespace ui { MockInputMethod::MockInputMethod(internal::InputMethodDelegate* delegate) - : text_input_client_(NULL), delegate_(delegate) { -} + : text_input_client_(nullptr), delegate_(delegate) {} MockInputMethod::~MockInputMethod() { for (InputMethodObserver& observer : observer_list_) @@ -35,7 +34,7 @@ void MockInputMethod::SetFocusedTextInputClient(TextInputClient* client) { void MockInputMethod::DetachTextInputClient(TextInputClient* client) { if (text_input_client_ == client) { - text_input_client_ = NULL; + text_input_client_ = nullptr; } } @@ -129,9 +128,4 @@ MockInputMethod::GetInputMethodKeyboardController() { return &keyboard_controller_; } -const std::vector>& -MockInputMethod::GetKeyEventsForTesting() { - return key_events_for_testing_; -} - } // namespace ui diff --git a/chromium/ui/base/ime/mock_input_method.h b/chromium/ui/base/ime/mock_input_method.h index 2d72e99a4bc..3cbfa920c9a 100644 --- a/chromium/ui/base/ime/mock_input_method.h +++ b/chromium/ui/base/ime/mock_input_method.h @@ -61,15 +61,11 @@ class COMPONENT_EXPORT(UI_BASE_IME) MockInputMethod : public InputMethod { InputMethodKeyboardController* GetInputMethodKeyboardController() override; private: - // InputMethod: - const std::vector>& GetKeyEventsForTesting() - override; TextInputClient* text_input_client_; base::ObserverList::Unchecked observer_list_; internal::InputMethodDelegate* delegate_; - std::vector> key_events_for_testing_; InputMethodKeyboardControllerStub keyboard_controller_; DISALLOW_COPY_AND_ASSIGN(MockInputMethod); diff --git a/chromium/ui/base/ime/mojom/BUILD.gn b/chromium/ui/base/ime/mojom/BUILD.gn index dd96cc53288..c69ea02d7a9 100644 --- a/chromium/ui/base/ime/mojom/BUILD.gn +++ b/chromium/ui/base/ime/mojom/BUILD.gn @@ -4,11 +4,33 @@ import("//mojo/public/tools/bindings/mojom.gni") +component("shared_mojom_traits") { + output_name = "ime_shared_mojom_traits" + defines = [ "IS_IME_SHARED_MOJOM_TRAITS_IMPL" ] + sources = [ + "ime_types_mojom_traits.cc", + "ime_types_mojom_traits.h", + ] + public_deps = [ + ":mojom_shared", + "//ipc:param_traits", + "//ui/base/ime:ime_types", + ] +} + mojom("mojom") { generate_java = true - sources = [ "ime_types.mojom" ] + sources = [ + "ime_types.mojom", + "text_input_state.mojom", + "virtual_keyboard_types.mojom", + ] - public_deps = [ "//mojo/public/mojom/base" ] + public_deps = [ + "//mojo/public/mojom/base", + "//ui/gfx/geometry/mojom", + "//ui/gfx/range/mojom", + ] cpp_typemaps = [ { @@ -25,20 +47,31 @@ mojom("mojom") { mojom = "ui.mojom.ImeTextSpanUnderlineStyle" cpp = "::ui::ImeTextSpan::UnderlineStyle" }, + { + mojom = "ui.mojom.TextInputAction" + cpp = "::ui::TextInputAction" + }, + { + mojom = "ui.mojom.TextInputMode" + cpp = "::ui::TextInputMode" + }, { mojom = "ui.mojom.TextInputType" cpp = "::ui::TextInputType" }, ] - traits_sources = [ "ime_types_mojom_traits.cc" ] traits_headers = [ "ime_types_mojom_traits.h" ] traits_public_deps = [ - "//ui/base/ime:ime_types", + ":shared_mojom_traits", "//ui/gfx/range", ] }, ] + blink_cpp_typemaps = cpp_typemaps + export_class_attribute_blink = "BLINK_PLATFORM_EXPORT" + export_define_blink = "BLINK_PLATFORM_IMPLEMENTATION=1" + export_header_blink = "third_party/blink/public/platform/web_common.h" } mojom("test_interfaces") { diff --git a/chromium/ui/base/ime/mojom/ime_types.mojom b/chromium/ui/base/ime/mojom/ime_types.mojom index 57b07029fa3..0c04bbfa900 100644 --- a/chromium/ui/base/ime/mojom/ime_types.mojom +++ b/chromium/ui/base/ime/mojom/ime_types.mojom @@ -6,6 +6,29 @@ module ui.mojom; import "mojo/public/mojom/base/string16.mojom"; +enum TextInputMode { + kDefault, + kNone, + kText, + kTel, + kUrl, + kEmail, + kNumeric, + kDecimal, + kSearch, +}; + +enum TextInputAction { + kDefault, + kEnter, + kDone, + kGo, + kNext, + kPrevious, + kSearch, + kSend, +}; + // Text input type which is based on blink::WebTextInputType. enum TextInputType { NONE, @@ -34,6 +57,7 @@ enum ImeTextSpanType { kComposition, kSuggestion, kMisspellingSuggestion, + kAutocorrect, }; // This enum represents the thickness of an underline segment of text, @@ -76,5 +100,6 @@ struct ImeTextSpan { uint32 background_color; uint32 suggestion_highlight_color; bool remove_on_finish_composing; + bool interim_char_selection; array suggestions; }; diff --git a/chromium/ui/base/ime/mojom/ime_types_mojom_traits.cc b/chromium/ui/base/ime/mojom/ime_types_mojom_traits.cc index 694959deddd..e09781c80e8 100644 --- a/chromium/ui/base/ime/mojom/ime_types_mojom_traits.cc +++ b/chromium/ui/base/ime/mojom/ime_types_mojom_traits.cc @@ -6,6 +6,99 @@ namespace mojo { +#define UI_TO_MOJO_ACTION_CASE(name) \ + case ui::TextInputAction::name: \ + return ui::mojom::TextInputAction::name + +// static +ui::mojom::TextInputAction +EnumTraits::ToMojom( + ui::TextInputAction text_input_action) { + switch (text_input_action) { + UI_TO_MOJO_ACTION_CASE(kDefault); + UI_TO_MOJO_ACTION_CASE(kEnter); + UI_TO_MOJO_ACTION_CASE(kDone); + UI_TO_MOJO_ACTION_CASE(kGo); + UI_TO_MOJO_ACTION_CASE(kNext); + UI_TO_MOJO_ACTION_CASE(kPrevious); + UI_TO_MOJO_ACTION_CASE(kSearch); + UI_TO_MOJO_ACTION_CASE(kSend); + } +} + +#undef UI_TO_MOJO_ACTION_CASE + +#define MOJO_TO_UI_ACTION_CASE(name) \ + case ui::mojom::TextInputAction::name: \ + *out = ui::TextInputAction::name; \ + return true; + +// static +bool EnumTraits::FromMojom( + ui::mojom::TextInputAction input, + ui::TextInputAction* out) { + switch (input) { + MOJO_TO_UI_ACTION_CASE(kDefault); + MOJO_TO_UI_ACTION_CASE(kEnter); + MOJO_TO_UI_ACTION_CASE(kDone); + MOJO_TO_UI_ACTION_CASE(kGo); + MOJO_TO_UI_ACTION_CASE(kNext); + MOJO_TO_UI_ACTION_CASE(kPrevious); + MOJO_TO_UI_ACTION_CASE(kSearch); + MOJO_TO_UI_ACTION_CASE(kSend); + } + return false; +} + +#undef MOJO_TO_UI_ACTION_CASE + +#define UI_TO_MOJO_MODE_CASE(name, mojo_name) \ + case ui::TextInputMode::TEXT_INPUT_MODE_##name: \ + return ui::mojom::TextInputMode::mojo_name + +// static +ui::mojom::TextInputMode +EnumTraits::ToMojom( + ui::TextInputMode text_input_mode) { + switch (text_input_mode) { + UI_TO_MOJO_MODE_CASE(DEFAULT, kDefault); + UI_TO_MOJO_MODE_CASE(NONE, kNone); + UI_TO_MOJO_MODE_CASE(TEXT, kText); + UI_TO_MOJO_MODE_CASE(TEL, kTel); + UI_TO_MOJO_MODE_CASE(URL, kUrl); + UI_TO_MOJO_MODE_CASE(EMAIL, kEmail); + UI_TO_MOJO_MODE_CASE(NUMERIC, kNumeric); + UI_TO_MOJO_MODE_CASE(DECIMAL, kDecimal); + UI_TO_MOJO_MODE_CASE(SEARCH, kSearch); + } +} + +#undef UI_TO_MOJO_MODE_CASE + +#define MOJO_TO_UI_MODE_CASE(name, mojo_name) \ + case ui::mojom::TextInputMode::mojo_name: \ + *out = ui::TextInputMode::TEXT_INPUT_MODE_##name; \ + return true; + +// static +bool EnumTraits::FromMojom( + ui::mojom::TextInputMode input, + ui::TextInputMode* out) { + switch (input) { + MOJO_TO_UI_MODE_CASE(DEFAULT, kDefault); + MOJO_TO_UI_MODE_CASE(NONE, kNone); + MOJO_TO_UI_MODE_CASE(TEXT, kText); + MOJO_TO_UI_MODE_CASE(TEL, kTel); + MOJO_TO_UI_MODE_CASE(URL, kUrl); + MOJO_TO_UI_MODE_CASE(EMAIL, kEmail); + MOJO_TO_UI_MODE_CASE(NUMERIC, kNumeric); + MOJO_TO_UI_MODE_CASE(DECIMAL, kDecimal); + MOJO_TO_UI_MODE_CASE(SEARCH, kSearch); + } +} + +#undef MOJO_TO_UI_MODE_CASE + #define UI_TO_MOJO_TYPE_CASE(name) \ case ui::TEXT_INPUT_TYPE_##name: \ return ui::mojom::TextInputType::name @@ -97,6 +190,7 @@ bool StructTraits::Read( out->background_color = data.background_color(); out->suggestion_highlight_color = data.suggestion_highlight_color(); out->remove_on_finish_composing = data.remove_on_finish_composing(); + out->interim_char_selection = data.interim_char_selection(); if (!data.ReadSuggestions(&out->suggestions)) return false; return true; @@ -113,6 +207,8 @@ EnumTraits::ToMojom( return ui::mojom::ImeTextSpanType::kSuggestion; case ui::ImeTextSpan::Type::kMisspellingSuggestion: return ui::mojom::ImeTextSpanType::kMisspellingSuggestion; + case ui::ImeTextSpan::Type::kAutocorrect: + return ui::mojom::ImeTextSpanType::kAutocorrect; } NOTREACHED(); @@ -133,6 +229,9 @@ bool EnumTraits::FromMojom( case ui::mojom::ImeTextSpanType::kMisspellingSuggestion: *out = ui::ImeTextSpan::Type::kMisspellingSuggestion; return true; + case ui::mojom::ImeTextSpanType::kAutocorrect: + *out = ui::ImeTextSpan::Type::kAutocorrect; + return true; } NOTREACHED(); diff --git a/chromium/ui/base/ime/mojom/ime_types_mojom_traits.h b/chromium/ui/base/ime/mojom/ime_types_mojom_traits.h index 58d192e2910..50489fadc75 100644 --- a/chromium/ui/base/ime/mojom/ime_types_mojom_traits.h +++ b/chromium/ui/base/ime/mojom/ime_types_mojom_traits.h @@ -7,20 +7,41 @@ #include +#include "base/component_export.h" #include "ui/base/ime/ime_text_span.h" -#include "ui/base/ime/mojom/ime_types.mojom.h" +#include "ui/base/ime/mojom/ime_types.mojom-shared.h" +#include "ui/base/ime/text_input_action.h" +#include "ui/base/ime/text_input_mode.h" #include "ui/base/ime/text_input_type.h" namespace mojo { template <> -struct EnumTraits { +struct COMPONENT_EXPORT(IME_SHARED_MOJOM_TRAITS) + EnumTraits { + static ui::mojom::TextInputMode ToMojom(ui::TextInputMode text_input_mode); + static bool FromMojom(ui::mojom::TextInputMode input, ui::TextInputMode* out); +}; + +template <> +struct COMPONENT_EXPORT(IME_SHARED_MOJOM_TRAITS) + EnumTraits { + static ui::mojom::TextInputAction ToMojom( + ui::TextInputAction text_input_action); + static bool FromMojom(ui::mojom::TextInputAction input, + ui::TextInputAction* out); +}; + +template <> +struct COMPONENT_EXPORT(IME_SHARED_MOJOM_TRAITS) + EnumTraits { static ui::mojom::TextInputType ToMojom(ui::TextInputType text_input_type); static bool FromMojom(ui::mojom::TextInputType input, ui::TextInputType* out); }; template <> -struct StructTraits { +struct COMPONENT_EXPORT(IME_SHARED_MOJOM_TRAITS) + StructTraits { static ui::ImeTextSpan::Type type(const ui::ImeTextSpan& c) { return c.type; } static uint32_t start_offset(const ui::ImeTextSpan& c) { return c.start_offset; @@ -46,6 +67,9 @@ struct StructTraits { static bool remove_on_finish_composing(const ui::ImeTextSpan& c) { return c.remove_on_finish_composing; } + static bool interim_char_selection(const ui::ImeTextSpan& c) { + return c.interim_char_selection; + } static std::vector suggestions(const ui::ImeTextSpan& c) { return c.suggestions; } @@ -53,7 +77,8 @@ struct StructTraits { }; template <> -struct EnumTraits { +struct COMPONENT_EXPORT(IME_SHARED_MOJOM_TRAITS) + EnumTraits { static ui::mojom::ImeTextSpanType ToMojom( ui::ImeTextSpan::Type ime_text_span_type); static bool FromMojom(ui::mojom::ImeTextSpanType input, @@ -61,7 +86,8 @@ struct EnumTraits { }; template <> -struct EnumTraits { +struct COMPONENT_EXPORT(IME_SHARED_MOJOM_TRAITS) + EnumTraits { static ui::mojom::ImeTextSpanThickness ToMojom( ui::ImeTextSpan::Thickness thickness); static bool FromMojom(ui::mojom::ImeTextSpanThickness input, @@ -69,8 +95,9 @@ struct EnumTraits { }; template <> -struct EnumTraits { +struct COMPONENT_EXPORT(IME_SHARED_MOJOM_TRAITS) + EnumTraits { static ui::mojom::ImeTextSpanUnderlineStyle ToMojom( ui::ImeTextSpan::UnderlineStyle underline_style); static bool FromMojom(ui::mojom::ImeTextSpanUnderlineStyle input, diff --git a/chromium/ui/base/ime/mojom/text_input_state.mojom b/chromium/ui/base/ime/mojom/text_input_state.mojom new file mode 100644 index 00000000000..63746cb4d67 --- /dev/null +++ b/chromium/ui/base/ime/mojom/text_input_state.mojom @@ -0,0 +1,68 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module ui.mojom; + +import "mojo/public/mojom/base/string16.mojom"; +import "mojo/public/mojom/base/text_direction.mojom"; +import "ui/base/ime/mojom/ime_types.mojom"; +import "ui/base/ime/mojom/virtual_keyboard_types.mojom"; +import "ui/gfx/geometry/mojom/geometry.mojom"; +import "ui/gfx/range/mojom/range.mojom"; + +// This structure represents the current editing state. +struct TextInputState { + // Type of the input field. + ui.mojom.TextInputType type = ui.mojom.TextInputType.NONE; + + // The mode of input field. + ui.mojom.TextInputMode mode = ui.mojom.TextInputMode.kDefault; + + // The action of the input field. + ui.mojom.TextInputAction action = ui.mojom.TextInputAction.kDefault; + + // The flags of input field (autocorrect, autocomplete, etc.) + // See ui/base/ime/text_input_flags.h for definitions. + uint32 flags; + + // The value of input field. + mojo_base.mojom.String16? value; + + // The current selection range, or the caret position if nothing is selected. + gfx.mojom.Range selection; + + // The current composition range if there is one. + gfx.mojom.Range? composition; + + // Whether or not inline composition can be performed for the current input. + bool can_compose_inline = true; + + // Whether or not the IME should be shown as a result of this update. Even if + // true, the IME will only be shown if the input is appropriate (e.g. not + // TEXT_INPUT_TYPE_NONE). + bool show_ime_if_needed; + + // Whether or not the IME should always be hidden as a result of this update. + bool always_hide_ime; + + // Whether or not this is a reply to a request from IME. + bool reply_to_request; + + // Store control and selection bounds of EditContext. + // These optionals will be nullopts if there isn't any active EditContext. + // For non EditContext scenarios, the bounds are returned via + // |GetCompositionCharacterBounds| + gfx.mojom.Rect? edit_context_control_bounds; + gfx.mojom.Rect? edit_context_selection_bounds; + + // The virtualkeyboardpolicy of the input field. + ui.mojom.VirtualKeyboardPolicy vk_policy = + ui.mojom.VirtualKeyboardPolicy.AUTO; + + // Whether or not show()/hide() API is called from VirtualKeyboard by web + // authors when the virtualkeyboardpolicy is manual. + ui.mojom.VirtualKeyboardVisibilityRequest last_vk_visibility_request = + ui.mojom.VirtualKeyboardVisibilityRequest.NONE; +}; + diff --git a/chromium/ui/base/ime/mojom/virtual_keyboard_types.mojom b/chromium/ui/base/ime/mojom/virtual_keyboard_types.mojom new file mode 100644 index 00000000000..d1cd8d038f7 --- /dev/null +++ b/chromium/ui/base/ime/mojom/virtual_keyboard_types.mojom @@ -0,0 +1,20 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module ui.mojom; + +// This mode corresponds to virtualkeyboardpolicy +// https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/VirtualKeyboardPolicy/explainer.md +enum VirtualKeyboardPolicy { + AUTO, + MANUAL, +}; + +// This mode corresponds to VirtualKeyboard API show/hide. +// https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/VirtualKeyboardPolicy/explainer.md +enum VirtualKeyboardVisibilityRequest { + SHOW, + HIDE, + NONE, +}; diff --git a/chromium/ui/base/ime/text_input_client.h b/chromium/ui/base/ime/text_input_client.h index 7fc2d584a94..b6302623328 100644 --- a/chromium/ui/base/ime/text_input_client.h +++ b/chromium/ui/base/ime/text_input_client.h @@ -217,6 +217,13 @@ class COMPONENT_EXPORT(UI_BASE_IME) TextInputClient { const std::vector& ui_ime_text_spans) = 0; #endif +#if defined(OS_CHROMEOS) + // Set the autocorrect range and return if it has been set correctly as a + // boolean value. + virtual bool SetAutocorrectRange(const base::string16& autocorrect_text, + const gfx::Range& range) = 0; +#endif + #if defined(OS_WIN) // Returns false if either the focused editable element or the EditContext // bounds is not available, else it returns true with the control and diff --git a/chromium/ui/base/ime/virtual_keyboard_visibility_request.h b/chromium/ui/base/ime/virtual_keyboard_visibility_request.h deleted file mode 100644 index 65cee20f299..00000000000 --- a/chromium/ui/base/ime/virtual_keyboard_visibility_request.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_IME_VIRTUAL_KEYBOARD_VISIBILITY_REQUEST_H_ -#define UI_BASE_IME_VIRTUAL_KEYBOARD_VISIBILITY_REQUEST_H_ - -namespace ui { - -// This mode corresponds to VirtualKeyboard API show/hide. -// https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/VirtualKeyboardPolicy/explainer.md -enum class VirtualKeyboardVisibilityRequest { - SHOW, - HIDE, - NONE, - MAX = NONE, -}; - -} // namespace ui - -#endif // UI_BASE_IME_VIRTUAL_KEYBOARD_VISIBILITY_REQUEST_H_ diff --git a/chromium/ui/base/ime/win/input_method_win_base.cc b/chromium/ui/base/ime/win/input_method_win_base.cc index 83850840d83..fc9c8d3a0f2 100644 --- a/chromium/ui/base/ime/win/input_method_win_base.cc +++ b/chromium/ui/base/ime/win/input_method_win_base.cc @@ -13,8 +13,6 @@ #include "base/command_line.h" #include "base/memory/ptr_util.h" #include "base/win/windows_version.h" -#include "ui/base/ime/ime_bridge.h" -#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/text_input_client.h" #include "ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.h" #include "ui/base/ime/win/on_screen_keyboard_display_manager_tab_tip.h" @@ -237,21 +235,6 @@ ui::EventDispatchDetails InputMethodWinBase::DispatchKeyEvent( !std::iswcntrl(static_cast(char_msgs[0].wParam))) event->set_character(static_cast(char_msgs[0].wParam)); - // Dispatches the key events to the Chrome IME extension which is listening to - // key events on the following two situations: - // 1) |char_msgs| is empty when the event is non-character key. - // 2) |char_msgs|.size() == 1 when the event is character key and the WM_CHAR - // messages have been combined in the event processing flow. - if (char_msgs.size() <= 1 && GetEngine()) { - ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback = - base::BindOnce(&InputMethodWinBase::ProcessKeyEventDone, - weak_ptr_factory_.GetWeakPtr(), - base::Owned(new ui::KeyEvent(*event)), - base::Owned(new std::vector(char_msgs))); - GetEngine()->ProcessKeyEvent(*event, std::move(callback)); - return ui::EventDispatchDetails(); - } - return ProcessUnhandledKeyEvent(event, &char_msgs); } @@ -506,48 +489,4 @@ ui::EventDispatchDetails InputMethodWinBase::ProcessUnhandledKeyEvent( return details; } -void InputMethodWinBase::UpdateCompositionBoundsForEngine( - const TextInputClient* client) { - TextInputType text_input_type = GetTextInputType(); - if (client == GetTextInputClient() && - text_input_type != TEXT_INPUT_TYPE_NONE && - text_input_type != TEXT_INPUT_TYPE_PASSWORD && GetEngine()) { - GetEngine()->SetCompositionBounds(GetCompositionBounds(client)); - } -} - -void InputMethodWinBase::ResetEngine() { - if (GetEngine()) - GetEngine()->Reset(); -} - -void InputMethodWinBase::CancelCompositionForEngine() { - TextInputType text_input_type = GetTextInputType(); - if (text_input_type != TEXT_INPUT_TYPE_NONE && - text_input_type != TEXT_INPUT_TYPE_PASSWORD) { - InputMethodWinBase::ResetEngine(); - } -} - -void InputMethodWinBase::UpdateEngineFocusAndInputContext() { - if (!ui::IMEBridge::Get()) // IMEBridge could be null for tests. - return; - - const TextInputType old_text_input_type = - ui::IMEBridge::Get()->GetCurrentInputContext().type; - ui::IMEEngineHandlerInterface::InputContext context( - GetTextInputType(), GetTextInputMode(), GetTextInputFlags(), - ui::TextInputClient::FOCUS_REASON_OTHER, GetClientShouldDoLearning()); - ui::IMEBridge::Get()->SetCurrentInputContext(context); - - // Update IME Engine state. - ui::IMEEngineHandlerInterface* engine = GetEngine(); - if (engine) { - if (old_text_input_type != ui::TEXT_INPUT_TYPE_NONE) - engine->FocusOut(); - if (GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) - engine->FocusIn(context); - } -} - } // namespace ui diff --git a/chromium/ui/base/ime/win/input_method_win_base.h b/chromium/ui/base/ime/win/input_method_win_base.h index 139d966dc0e..c788c6b5f35 100644 --- a/chromium/ui/base/ime/win/input_method_win_base.h +++ b/chromium/ui/base/ime/win/input_method_win_base.h @@ -62,19 +62,6 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) InputMethodWinBase ui::KeyEvent* event, const std::vector* char_msgs); - // Update composition bounds for Chromium IME extension. - void UpdateCompositionBoundsForEngine(const TextInputClient* client); - - // Reset composition status for Chromium IME extension. - void ResetEngine(); - - // Cancel composition for Chromium IME extension. - void CancelCompositionForEngine(); - - // Update focus state for Chromium IME extension and update input context in - // ui::IMEBridge. - void UpdateEngineFocusAndInputContext(); - // The toplevel window handle. const HWND toplevel_window_handle_; diff --git a/chromium/ui/base/ime/win/input_method_win_imm32.cc b/chromium/ui/base/ime/win/input_method_win_imm32.cc index 7c0ee3ee966..324a6bc91fb 100644 --- a/chromium/ui/base/ime/win/input_method_win_imm32.cc +++ b/chromium/ui/base/ime/win/input_method_win_imm32.cc @@ -12,8 +12,6 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/metrics/histogram_macros.h" -#include "ui/base/ime/ime_bridge.h" -#include "ui/base/ime/ime_engine_handler_interface.h" #include "ui/base/ime/text_input_client.h" #include "ui/base/ime/win/tsf_input_scope.h" #include "ui/display/win/screen_win.h" @@ -101,7 +99,6 @@ void InputMethodWinImm32::OnCaretBoundsChanged(const TextInputClient* client) { if (!IsTextInputClientFocused(client) || !IsWindowFocused(client)) return; NotifyTextInputCaretBoundsChanged(client); - InputMethodWinBase::UpdateCompositionBoundsForEngine(client); if (!enabled_) return; @@ -126,13 +123,8 @@ void InputMethodWinImm32::OnCaretBoundsChanged(const TextInputClient* client) { } void InputMethodWinImm32::CancelComposition(const TextInputClient* client) { - if (IsTextInputClientFocused(client)) { - // |enabled_| == false could be faked, and the engine should rely on the - // real type get from GetTextInputType(). - InputMethodWinBase::CancelCompositionForEngine(); - - if (enabled_) - imm32_manager_.CancelIME(toplevel_window_handle_); + if (IsTextInputClientFocused(client) && enabled_) { + imm32_manager_.CancelIME(toplevel_window_handle_); } } @@ -326,8 +318,6 @@ void InputMethodWinImm32::RefreshInputLanguage() { void InputMethodWinImm32::ConfirmCompositionText(bool reset_engine, bool keep_selection) { InputMethodBase::ConfirmCompositionText(reset_engine, keep_selection); - if (reset_engine) - InputMethodWinBase::ResetEngine(); // Makes sure the native IME app can be informed about the composition is // cleared, so that it can clean up its internal states. @@ -339,8 +329,7 @@ void InputMethodWinImm32::UpdateIMEState() { // Use switch here in case we are going to add more text input types. // We disable input method in password field. const HWND window_handle = toplevel_window_handle_; - const TextInputType text_input_type = - GetEngine() ? TEXT_INPUT_TYPE_NONE : GetTextInputType(); + const TextInputType text_input_type = GetTextInputType(); const TextInputMode text_input_mode = GetTextInputMode(); switch (text_input_type) { case ui::TEXT_INPUT_TYPE_NONE: @@ -357,8 +346,6 @@ void InputMethodWinImm32::UpdateIMEState() { imm32_manager_.SetTextInputMode(window_handle, text_input_mode); tsf_inputscope::SetInputScopeForTsfUnawareWindow( window_handle, text_input_type, text_input_mode); - - InputMethodWinBase::UpdateEngineFocusAndInputContext(); } } // namespace ui diff --git a/chromium/ui/base/ime/win/input_method_win_tsf.cc b/chromium/ui/base/ime/win/input_method_win_tsf.cc index 58926e51a7f..b4e4fcc2e67 100644 --- a/chromium/ui/base/ime/win/input_method_win_tsf.cc +++ b/chromium/ui/base/ime/win/input_method_win_tsf.cc @@ -100,7 +100,6 @@ void InputMethodWinTSF::OnTextInputTypeChanged(const TextInputClient* client) { } ui::TSFBridge::GetInstance()->CancelComposition(); ui::TSFBridge::GetInstance()->OnTextInputTypeChanged(client); - InputMethodWinBase::UpdateEngineFocusAndInputContext(); } void InputMethodWinTSF::OnCaretBoundsChanged(const TextInputClient* client) { @@ -110,14 +109,12 @@ void InputMethodWinTSF::OnCaretBoundsChanged(const TextInputClient* client) { } NotifyTextInputCaretBoundsChanged(client); ui::TSFBridge::GetInstance()->OnTextLayoutChanged(); - InputMethodWinBase::UpdateCompositionBoundsForEngine(client); } void InputMethodWinTSF::CancelComposition(const TextInputClient* client) { if (ui::TSFBridge::GetInstance() && IsTextInputClientFocused(client) && IsWindowFocused(client)) { ui::TSFBridge::GetInstance()->CancelComposition(); - InputMethodWinBase::CancelCompositionForEngine(); } } @@ -181,8 +178,6 @@ void InputMethodWinTSF::ConfirmCompositionText(bool reset_engine, if (IsTextInputTypeNone()) return; - if (reset_engine && GetTextInputClient()->HasCompositionText()) - InputMethodWinBase::ResetEngine(); if (ui::TSFBridge::GetInstance()) ui::TSFBridge::GetInstance()->ConfirmComposition(); } diff --git a/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.cc b/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.cc index cf2caabef7d..5c19abd64d6 100644 --- a/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.cc +++ b/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.cc @@ -222,7 +222,7 @@ void OnScreenKeyboardDisplayManagerInputPane::Run() { // Execute show() or hide() on the background thread after the debounce // expires. switch (last_vk_visibility_request_) { - case VirtualKeyboardVisibilityRequest::SHOW: { + case mojom::VirtualKeyboardVisibilityRequest::SHOW: { background_task_runner_->PostTask( FROM_HERE, base::BindOnce( @@ -231,7 +231,7 @@ void OnScreenKeyboardDisplayManagerInputPane::Run() { base::RetainedRef(virtual_keyboard_input_pane_), hwnd_)); break; } - case VirtualKeyboardVisibilityRequest::HIDE: { + case mojom::VirtualKeyboardVisibilityRequest::HIDE: { background_task_runner_->PostTask( FROM_HERE, base::BindOnce( @@ -240,18 +240,18 @@ void OnScreenKeyboardDisplayManagerInputPane::Run() { base::RetainedRef(virtual_keyboard_input_pane_), hwnd_)); break; } - case VirtualKeyboardVisibilityRequest::NONE: { + case mojom::VirtualKeyboardVisibilityRequest::NONE: { break; } } // Reset the VK visibility state to none so we can keep track of subsequent // API calls. - last_vk_visibility_request_ = VirtualKeyboardVisibilityRequest::NONE; + last_vk_visibility_request_ = mojom::VirtualKeyboardVisibilityRequest::NONE; } bool OnScreenKeyboardDisplayManagerInputPane::DisplayVirtualKeyboard() { DCHECK(main_task_runner_->BelongsToCurrentThread()); - last_vk_visibility_request_ = VirtualKeyboardVisibilityRequest::SHOW; + last_vk_visibility_request_ = mojom::VirtualKeyboardVisibilityRequest::SHOW; debouncer_->RequestRun(base::BindOnce( &OnScreenKeyboardDisplayManagerInputPane::Run, base::Unretained(this))); return true; @@ -259,7 +259,7 @@ bool OnScreenKeyboardDisplayManagerInputPane::DisplayVirtualKeyboard() { void OnScreenKeyboardDisplayManagerInputPane::DismissVirtualKeyboard() { DCHECK(main_task_runner_->BelongsToCurrentThread()); - last_vk_visibility_request_ = VirtualKeyboardVisibilityRequest::HIDE; + last_vk_visibility_request_ = mojom::VirtualKeyboardVisibilityRequest::HIDE; debouncer_->RequestRun(base::BindOnce( &OnScreenKeyboardDisplayManagerInputPane::Run, base::Unretained(this))); } diff --git a/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.h b/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.h index 40c8578cb79..68b15c27f21 100644 --- a/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.h +++ b/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_input_pane.h @@ -18,7 +18,7 @@ #include "base/threading/thread_task_runner_handle.h" #include "base/win/windows_types.h" #include "ui/base/ime/input_method_keyboard_controller.h" -#include "ui/base/ime/virtual_keyboard_visibility_request.h" +#include "ui/base/ime/mojom/virtual_keyboard_types.mojom-shared.h" #include "ui/base/ime/win/virtual_keyboard_debounce_timer.h" #include "ui/gfx/geometry/rect.h" @@ -47,8 +47,8 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) pane); // Returns whether show/hide VK API is called from // InputMethodKeyboardController or not. - VirtualKeyboardVisibilityRequest GetLastVirtualKeyboardVisibilityRequest() - const { + mojom::VirtualKeyboardVisibilityRequest + GetLastVirtualKeyboardVisibilityRequest() const { return last_vk_visibility_request_; } @@ -69,8 +69,8 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) const scoped_refptr background_task_runner_; scoped_refptr virtual_keyboard_input_pane_; bool is_keyboard_visible_; - VirtualKeyboardVisibilityRequest last_vk_visibility_request_ = - VirtualKeyboardVisibilityRequest::NONE; + mojom::VirtualKeyboardVisibilityRequest last_vk_visibility_request_ = + mojom::VirtualKeyboardVisibilityRequest::NONE; std::unique_ptr debouncer_; base::WeakPtrFactory weak_factory_{ this}; diff --git a/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_tab_tip.h b/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_tab_tip.h index c32989e65b7..f718926d662 100644 --- a/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_tab_tip.h +++ b/chromium/ui/base/ime/win/on_screen_keyboard_display_manager_tab_tip.h @@ -11,7 +11,6 @@ #include "base/observer_list.h" #include "base/strings/string16.h" #include "ui/base/ime/input_method_keyboard_controller.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/geometry/rect.h" namespace ui { diff --git a/chromium/ui/base/ime/win/tsf_bridge.cc b/chromium/ui/base/ime/win/tsf_bridge.cc index 778f19bb853..f5c8c7155d4 100644 --- a/chromium/ui/base/ime/win/tsf_bridge.cc +++ b/chromium/ui/base/ime/win/tsf_bridge.cc @@ -111,6 +111,10 @@ class TSFBridgeImpl : public TSFBridge { // An ITfThreadMgr object to be used in focus and document management. Microsoft::WRL::ComPtr thread_manager_; + // An ITfInputProcessorProfiles object to be used to get current language + // locale profile. + Microsoft::WRL::ComPtr input_processor_profiles_; + // A map from TextInputType to an editable document for TSF. We use multiple // TSF documents that have different InputScopes and TSF attributes based on // the TextInputType associated with the target document. For a TextInputType @@ -134,6 +138,9 @@ class TSFBridgeImpl : public TSFBridge { // Handle to ITfKeyTraceEventSink. DWORD key_trace_sink_cookie_ = 0; + // Handle to ITfLanguageProfileNotifySink + DWORD language_profile_cookie_ = 0; + DISALLOW_COPY_AND_ASSIGN(TSFBridgeImpl); }; @@ -149,6 +156,11 @@ TSFBridgeImpl::~TSFBridgeImpl() { if (SUCCEEDED(thread_manager_->QueryInterface(IID_PPV_ARGS(&source)))) { source->UnadviseSink(key_trace_sink_cookie_); } + Microsoft::WRL::ComPtr language_source; + if (SUCCEEDED(input_processor_profiles_->QueryInterface( + IID_PPV_ARGS(&language_source)))) { + language_source->UnadviseSink(language_profile_cookie_); + } } for (TSFDocumentMap::iterator it = tsf_document_map_.begin(); @@ -174,6 +186,13 @@ bool TSFBridgeImpl::Initialize() { return false; } + if (FAILED(::CoCreateInstance(CLSID_TF_InputProcessorProfiles, nullptr, + CLSCTX_ALL, + IID_PPV_ARGS(&input_processor_profiles_)))) { + DVLOG(1) << "Failed to create InputProcessorProfiles instance."; + return false; + } + if (FAILED(::CoCreateInstance(CLSID_TF_ThreadMgr, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&thread_manager_)))) { DVLOG(1) << "Failed to create ThreadManager instance."; @@ -309,7 +328,8 @@ void TSFBridgeImpl::SetFocusedClient(HWND focused_window, void TSFBridgeImpl::RemoveFocusedClient(TextInputClient* client) { DCHECK(base::MessageLoopCurrentForUI::IsSet()); - DCHECK(IsInitialized()); + if (!IsInitialized()) + return; if (client_ != client) return; ClearAssociateFocus(); @@ -422,6 +442,21 @@ bool TSFBridgeImpl::CreateDocumentManager(TSFTextStore* text_store, return false; } + Microsoft::WRL::ComPtr language_source; + if (FAILED(input_processor_profiles_->QueryInterface( + IID_PPV_ARGS(&language_source)))) { + DVLOG(1) << "Failed to get source_ITfInputProcessorProfiles."; + return false; + } + + if (FAILED( + language_source->AdviseSink(IID_ITfLanguageProfileNotifySink, + static_cast(text_store), + &language_profile_cookie_))) { + DVLOG(1) << "AdviseSink for language profile notify sink failed."; + return false; + } + if (*source_cookie == TF_INVALID_COOKIE) { DVLOG(1) << "The result of cookie is invalid."; return false; diff --git a/chromium/ui/base/ime/win/tsf_text_store.cc b/chromium/ui/base/ime/win/tsf_text_store.cc index 22f43ff72b0..98ca302320d 100644 --- a/chromium/ui/base/ime/win/tsf_text_store.cc +++ b/chromium/ui/base/ime/win/tsf_text_store.cc @@ -11,6 +11,7 @@ #include +#include "base/logging.h" #include "base/numerics/ranges.h" #include "base/win/scoped_variant.h" #include "ui/base/ime/text_input_client.h" @@ -80,6 +81,8 @@ HRESULT TSFTextStore::QueryInterface(REFIID iid, void** result) { *result = static_cast(this); } else if (iid == IID_ITfContextOwnerCompositionSink) { *result = static_cast(this); + } else if (iid == IID_ITfLanguageProfileNotifySink) { + *result = static_cast(this); } else if (iid == IID_ITfTextEditSink) { *result = static_cast(this); } else if (iid == IID_ITfKeyTraceEventSink) { @@ -647,9 +650,7 @@ HRESULT TSFTextStore::RequestLock(DWORD lock_flags, HRESULT* result) { // 3. User commits current composition text. if (((new_composition_start > last_composition_start && text_input_client_->HasCompositionText()) || - (wparam_keydown_fired_ == 0 && !has_composition_range_ && - !text_input_client_->HasCompositionText()) || - (wparam_keydown_fired_ != 0 && !has_composition_range_)) && + !has_composition_range_) && text_input_client_) { CommitTextAndEndCompositionIfAny(last_composition_start, new_composition_start); @@ -694,6 +695,7 @@ HRESULT TSFTextStore::RequestLock(DWORD lock_flags, HRESULT* result) { // reset the flag since we've already inserted/replaced the text. new_text_inserted_ = false; + is_selection_interim_char_ = false; // reset string_buffer_ if composition is no longer active. if (!text_input_client_->HasCompositionText()) { @@ -760,6 +762,7 @@ HRESULT TSFTextStore::SetSelection(ULONG selection_buffer_size, } selection_.set_start(start_pos); selection_.set_end(end_pos); + is_selection_interim_char_ = selection_buffer[0].style.fInterimChar; } return S_OK; } @@ -829,6 +832,15 @@ HRESULT TSFTextStore::OnEndComposition(ITfCompositionView* composition_view) { return S_OK; } +HRESULT TSFTextStore::OnLanguageChange(LANGID langid, BOOL* pfAccept) { + return S_OK; +} +HRESULT TSFTextStore::OnLanguageChanged() { + if (text_input_client_) + text_input_client_->OnInputMethodChanged(); + return S_OK; +} + HRESULT TSFTextStore::OnKeyTraceDown(WPARAM wParam, LPARAM lParam) { // fire the event right away if we're in composition if (has_composition_range_) { @@ -1052,6 +1064,10 @@ bool TSFTextStore::GetCompositionStatus( span.end_offset = start_pos + length; span.underline_color = SK_ColorBLACK; span.background_color = SK_ColorTRANSPARENT; + if (selection_.EqualsIgnoringDirection( + gfx::Range(span.start_offset, span.end_offset))) { + span.interim_char_selection = is_selection_interim_char_; + } if (has_display_attribute) GetStyle(display_attribute, &span); spans->push_back(span); @@ -1355,8 +1371,11 @@ void TSFTextStore::CommitTextAndEndCompositionIfAny(size_t old_size, : new_committed_string_size); // TODO(crbug.com/978678): Unify the behavior of // |TextInputClient::InsertText(text)| for the empty text. - if (!new_committed_string.empty()) + if (!new_committed_string.empty()) { text_input_client_->InsertText(new_committed_string); + } else { + text_input_client_->ClearCompositionText(); + } // Notify accessibility about this committed composition text_input_client_->SetActiveCompositionForAccessibility( replace_text_range_, new_committed_string, diff --git a/chromium/ui/base/ime/win/tsf_text_store.h b/chromium/ui/base/ime/win/tsf_text_store.h index 10bbae5a50e..bf02704ffff 100644 --- a/chromium/ui/base/ime/win/tsf_text_store.h +++ b/chromium/ui/base/ime/win/tsf_text_store.h @@ -102,6 +102,7 @@ class TextInputClient; class COMPONENT_EXPORT(UI_BASE_IME_WIN) TSFTextStore : public ITextStoreACP, public ITfContextOwnerCompositionSink, + public ITfLanguageProfileNotifySink, public ITfKeyTraceEventSink, public ITfTextEditSink { public: @@ -216,6 +217,10 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) TSFTextStore IFACEMETHODIMP OnEndComposition( ITfCompositionView* composition_view) override; + // ITfLanguageProfileNotifySink: + IFACEMETHODIMP OnLanguageChange(LANGID langid, BOOL* pfAccept) override; + IFACEMETHODIMP OnLanguageChanged() override; + // ITfTextEditSink: IFACEMETHODIMP OnEndEdit(ITfContext* context, TfEditCookie read_only_edit_cookie, @@ -391,6 +396,10 @@ class COMPONENT_EXPORT(UI_BASE_IME_WIN) TSFTextStore // |selection_.end()|: 4 gfx::Range selection_; + // Indicates if the selection is an interim character. Please refer to + // https://docs.microsoft.com/en-us/windows/win32/api/textstor/ns-textstor-ts_selectionstyle + bool is_selection_interim_char_ = false; + // |start_offset| and |end_offset| of |text_spans_| indicates // the offsets in |string_buffer_document_|. // Example: "aoi" is committed. There are two underlines in "umi" and "no". diff --git a/chromium/ui/base/ime/win/tsf_text_store_unittest.cc b/chromium/ui/base/ime/win/tsf_text_store_unittest.cc index 081809d75a1..4e81d7c1012 100644 --- a/chromium/ui/base/ime/win/tsf_text_store_unittest.cc +++ b/chromium/ui/base/ime/win/tsf_text_store_unittest.cc @@ -3394,5 +3394,92 @@ TEST_F(TSFTextStoreTest, RegressionTest7) { EXPECT_EQ(S_OK, result); } +// regression tests for crbug.com/1091069. +// We should allow inserting empty compositon string to cancel composition. +class RegressionTest8Callback : public TSFTextStoreTestCallback { + public: + explicit RegressionTest8Callback(TSFTextStore* text_store) + : TSFTextStoreTestCallback(text_store) {} + + HRESULT LockGranted1(DWORD flags) { + SetTextTest(0, 0, L"bbbb", S_OK); + SetSelectionTest(0, 4, S_OK); + + text_spans()->clear(); + ImeTextSpan text_span_1; + text_span_1.start_offset = 0; + text_span_1.end_offset = 4; + text_span_1.underline_color = SK_ColorBLACK; + text_span_1.thickness = ImeTextSpan::Thickness::kThin; + text_span_1.background_color = SK_ColorTRANSPARENT; + text_spans()->push_back(text_span_1); + + *edit_flag() = true; + *composition_start() = 0; + composition_range()->set_start(0); + composition_range()->set_end(4); + *has_composition_range() = true; + + text_store_->OnKeyTraceDown(65u, 1966081u); + return S_OK; + } + + void SetCompositionText1(const ui::CompositionText& composition) { + EXPECT_EQ(L"bbbb", composition.text); + EXPECT_EQ(0u, composition.selection.start()); + EXPECT_EQ(4u, composition.selection.end()); + ASSERT_EQ(1u, composition.ime_text_spans.size()); + EXPECT_EQ(0u, composition.ime_text_spans[0].start_offset); + EXPECT_EQ(4u, composition.ime_text_spans[0].end_offset); + SetHasCompositionText(true); + } + + HRESULT LockGranted2(DWORD flags) { + GetTextTest(0, -1, L"bbbb", 4); + SetTextTest(0, 4, L"", S_OK); + + text_spans()->clear(); + *edit_flag() = true; + *composition_start() = 0; + composition_range()->set_start(0); + composition_range()->set_end(0); + + *has_composition_range() = false; + text_store_->OnKeyTraceUp(65u, 1966081u); + return S_OK; + } + + void ClearCompositionText2() { EXPECT_EQ(false, *has_composition_range()); } + + private: + DISALLOW_COPY_AND_ASSIGN(RegressionTest8Callback); +}; + +TEST_F(TSFTextStoreTest, RegressionTest8) { + RegressionTest8Callback callback(text_store_.get()); + EXPECT_CALL(text_input_client_, SetCompositionText(_)) + .WillOnce( + Invoke(&callback, &RegressionTest8Callback::SetCompositionText1)); + + EXPECT_CALL(text_input_client_, ClearCompositionText()) + .WillOnce( + Invoke(&callback, &RegressionTest8Callback::ClearCompositionText2)); + + EXPECT_CALL(*sink_, OnLockGranted(_)) + .WillOnce(Invoke(&callback, &RegressionTest8Callback::LockGranted1)) + .WillOnce(Invoke(&callback, &RegressionTest8Callback::LockGranted2)); + + ON_CALL(text_input_client_, HasCompositionText()) + .WillByDefault( + Invoke(&callback, &TSFTextStoreTestCallback::HasCompositionText)); + + HRESULT result = kInvalidResult; + EXPECT_EQ(S_OK, text_store_->RequestLock(TS_LF_READWRITE, &result)); + EXPECT_EQ(S_OK, result); + result = kInvalidResult; + EXPECT_EQ(S_OK, text_store_->RequestLock(TS_LF_READWRITE, &result)); + EXPECT_EQ(S_OK, result); +} + } // namespace } // namespace ui diff --git a/chromium/ui/base/l10n/formatter.cc b/chromium/ui/base/l10n/formatter.cc index 72ed375005f..e4446d4786f 100644 --- a/chromium/ui/base/l10n/formatter.cc +++ b/chromium/ui/base/l10n/formatter.cc @@ -7,9 +7,11 @@ #include #include +#include #include #include "base/check.h" +#include "base/component_export.h" #include "third_party/icu/source/common/unicode/unistr.h" #include "third_party/icu/source/i18n/unicode/msgfmt.h" #include "ui/base/l10n/l10n_util.h" @@ -17,7 +19,7 @@ namespace ui { -UI_BASE_EXPORT bool formatter_force_fallback = false; +COMPONENT_EXPORT(UI_BASE) bool formatter_force_fallback = false; struct Pluralities { int id; diff --git a/chromium/ui/base/l10n/formatter.h b/chromium/ui/base/l10n/formatter.h index 17ff00e9d2f..7d9478a48f9 100644 --- a/chromium/ui/base/l10n/formatter.h +++ b/chromium/ui/base/l10n/formatter.h @@ -10,13 +10,13 @@ #include +#include "base/component_export.h" #include "base/lazy_instance.h" #include "base/macros.h" #include "third_party/icu/source/common/unicode/unistr.h" #include "third_party/icu/source/i18n/unicode/msgfmt.h" #include "third_party/icu/source/i18n/unicode/plurrule.h" #include "ui/base/l10n/time_format.h" -#include "ui/base/ui_base_export.h" namespace ui { @@ -87,7 +87,7 @@ class Formatter { }; // Class to hold all Formatters, intended to be used in a global LazyInstance. -class UI_BASE_EXPORT FormatterContainer { +class COMPONENT_EXPORT(UI_BASE) FormatterContainer { public: FormatterContainer(); ~FormatterContainer(); @@ -112,10 +112,11 @@ class UI_BASE_EXPORT FormatterContainer { // Windows compilation requires full definition of FormatterContainer before // LazyInstance may be declared. -extern UI_BASE_EXPORT base::LazyInstance::Leaky g_container; +extern COMPONENT_EXPORT(UI_BASE) base::LazyInstance::Leaky + g_container; // For use in unit tests only. -extern UI_BASE_EXPORT bool formatter_force_fallback; +extern COMPONENT_EXPORT(UI_BASE) bool formatter_force_fallback; } // namespace ui diff --git a/chromium/ui/base/l10n/l10n_font_util.h b/chromium/ui/base/l10n/l10n_font_util.h index 8036566e879..81dffd348f1 100644 --- a/chromium/ui/base/l10n/l10n_font_util.h +++ b/chromium/ui/base/l10n/l10n_font_util.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_L10N_FONT_UTIL_H_ #define UI_BASE_L10N_FONT_UTIL_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" #include "ui/gfx/geometry/size.h" namespace gfx { @@ -18,13 +18,16 @@ namespace ui { // its localized size data and the given font. The width in cols is held in a // localized string resource identified by |col_resource_id|, the height in the // same fashion. -UI_BASE_EXPORT int GetLocalizedContentsWidthForFont(int col_resource_id, - const gfx::Font& font); -UI_BASE_EXPORT int GetLocalizedContentsHeightForFont(int row_resource_id, - const gfx::Font& font); -UI_BASE_EXPORT gfx::Size GetLocalizedContentsSizeForFont(int col_resource_id, - int row_resource_id, - const gfx::Font& font); +COMPONENT_EXPORT(UI_BASE) +int GetLocalizedContentsWidthForFont(int col_resource_id, + const gfx::Font& font); +COMPONENT_EXPORT(UI_BASE) +int GetLocalizedContentsHeightForFont(int row_resource_id, + const gfx::Font& font); +COMPONENT_EXPORT(UI_BASE) +gfx::Size GetLocalizedContentsSizeForFont(int col_resource_id, + int row_resource_id, + const gfx::Font& font); } // namespace ui diff --git a/chromium/ui/base/l10n/l10n_util.cc b/chromium/ui/base/l10n/l10n_util.cc index 489cde62132..29deb4da711 100644 --- a/chromium/ui/base/l10n/l10n_util.cc +++ b/chromium/ui/base/l10n/l10n_util.cc @@ -45,6 +45,7 @@ #endif #if defined(OS_WIN) +#include "base/logging.h" #include "ui/base/l10n/l10n_util_win.h" #endif // OS_WIN diff --git a/chromium/ui/base/l10n/l10n_util.h b/chromium/ui/base/l10n/l10n_util.h index 21de14825df..6a9af307289 100644 --- a/chromium/ui/base/l10n/l10n_util.h +++ b/chromium/ui/base/l10n/l10n_util.h @@ -14,9 +14,9 @@ #include #include +#include "base/component_export.h" #include "base/strings/string16.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" #if defined(OS_MACOSX) #include "ui/base/l10n/l10n_util_mac.h" @@ -25,12 +25,13 @@ namespace l10n_util { // Takes normalized locale as |locale|. Returns language part (before '-'). -UI_BASE_EXPORT std::string GetLanguage(const std::string& locale); +COMPONENT_EXPORT(UI_BASE) std::string GetLanguage(const std::string& locale); // This method translates a generic locale name to one of the locally defined // ones. This method returns true if it succeeds. -UI_BASE_EXPORT bool CheckAndResolveLocale(const std::string& locale, - std::string* resolved_locale); +COMPONENT_EXPORT(UI_BASE) +bool CheckAndResolveLocale(const std::string& locale, + std::string* resolved_locale); // This method is responsible for determining the locale as defined below. In // nearly all cases you shouldn't call this, rather use GetApplicationLocale @@ -42,17 +43,20 @@ UI_BASE_EXPORT bool CheckAndResolveLocale(const std::string& locale, // a value if there's a corresponding resource DLL for the locale. Otherwise, // we fall back to en-us. |set_icu_locale| determines whether the resulting // locale is set as the default ICU locale before returning it. -UI_BASE_EXPORT std::string GetApplicationLocale(const std::string& pref_locale, - bool set_icu_locale); +COMPONENT_EXPORT(UI_BASE) +std::string GetApplicationLocale(const std::string& pref_locale, + bool set_icu_locale); // Convenience version of GetApplicationLocale() that sets the resulting locale // as the default ICU locale before returning it. -UI_BASE_EXPORT std::string GetApplicationLocale(const std::string& pref_locale); +COMPONENT_EXPORT(UI_BASE) +std::string GetApplicationLocale(const std::string& pref_locale); // Returns true if a display name for |locale| is available in the locale // |display_locale|. -UI_BASE_EXPORT bool IsLocaleNameTranslated(const char* locale, - const std::string& display_locale); +COMPONENT_EXPORT(UI_BASE) +bool IsLocaleNameTranslated(const char* locale, + const std::string& display_locale); // Given a locale code, return true if the OS is capable of supporting it. // For instance, Oriya is not well supported on Windows XP and we return @@ -68,25 +72,27 @@ bool IsLocaleSupportedByOS(const std::string& locale); // in the UI thread. // If |is_for_ui| is true, U+200F is appended so that it can be // rendered properly in a RTL Chrome. -UI_BASE_EXPORT base::string16 GetDisplayNameForLocale( - const std::string& locale, - const std::string& display_locale, - bool is_for_ui, - bool disallow_default = false); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetDisplayNameForLocale(const std::string& locale, + const std::string& display_locale, + bool is_for_ui, + bool disallow_default = false); // Returns the display name of the |country_code| in |display_locale|. -UI_BASE_EXPORT base::string16 GetDisplayNameForCountry( - const std::string& country_code, - const std::string& display_locale); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetDisplayNameForCountry(const std::string& country_code, + const std::string& display_locale); // Converts all - into _, to be consistent with ICU and file system names. -UI_BASE_EXPORT std::string NormalizeLocale(const std::string& locale); +COMPONENT_EXPORT(UI_BASE) +std::string NormalizeLocale(const std::string& locale); // Produce a vector of parent locales for given locale. // It includes the current locale in the result. // sr_Cyrl_RS generates sr_Cyrl_RS, sr_Cyrl and sr. -UI_BASE_EXPORT void GetParentLocales(const std::string& current_locale, - std::vector* parent_locales); +COMPONENT_EXPORT(UI_BASE) +void GetParentLocales(const std::string& current_locale, + std::vector* parent_locales); // Checks if a string is plausibly a syntactically-valid locale string, // for cases where we want the valid input to be a locale string such as @@ -96,72 +102,81 @@ UI_BASE_EXPORT void GetParentLocales(const std::string& current_locale, // accepted, but 'z', 'German', 'en-$1', or 'abcd-1234' should not. // Case-insensitive. Based on BCP 47, see: // http://unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers -UI_BASE_EXPORT bool IsValidLocaleSyntax(const std::string& locale); +COMPONENT_EXPORT(UI_BASE) bool IsValidLocaleSyntax(const std::string& locale); // // Mac Note: See l10n_util_mac.h for some NSString versions and other support. // // Pulls resource string from the string bundle and returns it. -UI_BASE_EXPORT std::string GetStringUTF8(int message_id); -UI_BASE_EXPORT base::string16 GetStringUTF16(int message_id); +COMPONENT_EXPORT(UI_BASE) std::string GetStringUTF8(int message_id); +COMPONENT_EXPORT(UI_BASE) base::string16 GetStringUTF16(int message_id); // Get a resource string and replace $i with replacements[i] for all // i < replacements.size(). Additionally, $$ is replaced by $. // If non-NULL |offsets| will be replaced with the start points of the replaced // strings. -UI_BASE_EXPORT base::string16 GetStringFUTF16( - int message_id, - const std::vector& replacements, - std::vector* offsets); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, + const std::vector& replacements, + std::vector* offsets); // Convenience wrappers for the above. -UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, - const base::string16& a); -UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, - const base::string16& a, - const base::string16& b); -UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c); -UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c, - const base::string16& d); -UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c, - const base::string16& d, - const base::string16& e); -UI_BASE_EXPORT std::string GetStringFUTF8(int message_id, - const base::string16& a); -UI_BASE_EXPORT std::string GetStringFUTF8(int message_id, - const base::string16& a, - const base::string16& b); -UI_BASE_EXPORT std::string GetStringFUTF8(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c); -UI_BASE_EXPORT std::string GetStringFUTF8(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c, - const base::string16& d); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, const base::string16& a); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, + const base::string16& a, + const base::string16& b); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c, + const base::string16& d); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c, + const base::string16& d, + const base::string16& e); +COMPONENT_EXPORT(UI_BASE) +std::string GetStringFUTF8(int message_id, const base::string16& a); +COMPONENT_EXPORT(UI_BASE) +std::string GetStringFUTF8(int message_id, + const base::string16& a, + const base::string16& b); +COMPONENT_EXPORT(UI_BASE) +std::string GetStringFUTF8(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c); +COMPONENT_EXPORT(UI_BASE) +std::string GetStringFUTF8(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c, + const base::string16& d); // Variants that return the offset(s) of the replaced parameters. The // vector based version returns offsets ordered by parameter. For example if // invoked with a and b offsets[0] gives the offset for a and offsets[1] the // offset of b regardless of where the parameters end up in the string. -UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, - const base::string16& a, - size_t* offset); -UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, - const base::string16& a, - const base::string16& b, - std::vector* offsets); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, + const base::string16& a, + size_t* offset); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16(int message_id, + const base::string16& a, + const base::string16& b, + std::vector* offsets); // Convenience functions to get a string with a single integer as a parameter. // The result will use non-ASCII(native) digits if required by a locale @@ -174,7 +189,8 @@ UI_BASE_EXPORT base::string16 GetStringFUTF16(int message_id, // // Note that native digits have to be used in UI in general. // base::{Int*,Double}ToString convert a number to a string with // ASCII digits in non-UI strings. -UI_BASE_EXPORT base::string16 GetStringFUTF16Int(int message_id, int a); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetStringFUTF16Int(int message_id, int a); base::string16 GetStringFUTF16Int(int message_id, int64_t a); // Convenience functions to format a string with a single number that requires @@ -188,45 +204,51 @@ base::string16 GetStringFUTF16Int(int message_id, int64_t a); // double, time, string; e.g. "At 3:45 on Feb 3, 2016, 5 files are downloaded // at 3 MB/s."), use base::i18n::MessageFormatter. // message_format_unittests.cc also has more examples of plural formatting. -UI_BASE_EXPORT base::string16 GetPluralStringFUTF16(int message_id, int number); -UI_BASE_EXPORT std::string GetPluralStringFUTF8(int message_id, int number); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetPluralStringFUTF16(int message_id, int number); +COMPONENT_EXPORT(UI_BASE) +std::string GetPluralStringFUTF8(int message_id, int number); // Get a string when you only care about 'single vs multiple' distinction. // The message pointed to by |message_id| should be in ICU syntax // (see the references above for Plural) with 'single', 'multiple', and // 'other' (fallback) instead of 'male', 'female', and 'other' (fallback). -UI_BASE_EXPORT base::string16 GetSingleOrMultipleStringUTF16(int message_id, - bool is_multiple); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetSingleOrMultipleStringUTF16(int message_id, bool is_multiple); // In place sorting of base::string16 strings using collation rules for // |locale|. -UI_BASE_EXPORT void SortStrings16(const std::string& locale, - std::vector* strings); +COMPONENT_EXPORT(UI_BASE) +void SortStrings16(const std::string& locale, + std::vector* strings); // Returns a vector of available locale codes. E.g., a vector containing // en-US, es, fr, fi, pt-PT, pt-BR, etc. -UI_BASE_EXPORT const std::vector& GetAvailableLocales(); +COMPONENT_EXPORT(UI_BASE) const std::vector& GetAvailableLocales(); // Returns a vector of locale codes usable for accept-languages. -UI_BASE_EXPORT void GetAcceptLanguagesForLocale( - const std::string& display_locale, - std::vector* locale_codes); +COMPONENT_EXPORT(UI_BASE) +void GetAcceptLanguagesForLocale(const std::string& display_locale, + std::vector* locale_codes); // Returns a vector of untranslated locale codes usable for accept-languages. -UI_BASE_EXPORT void GetAcceptLanguages(std::vector* locale_codes); +COMPONENT_EXPORT(UI_BASE) +void GetAcceptLanguages(std::vector* locale_codes); // Returns true if |locale| is in a predefined AcceptLanguageList and // a display name for the |locale| is available in the locale |display_locale|. -UI_BASE_EXPORT bool IsLanguageAccepted(const std::string& display_locale, - const std::string& locale); +COMPONENT_EXPORT(UI_BASE) +bool IsLanguageAccepted(const std::string& display_locale, + const std::string& locale); // Returns the preferred size of the contents view of a window based on // designer given constraints which might dependent on the language used. -UI_BASE_EXPORT int GetLocalizedContentsWidthInPixels(int pixel_resource_id); +COMPONENT_EXPORT(UI_BASE) +int GetLocalizedContentsWidthInPixels(int pixel_resource_id); -UI_BASE_EXPORT const char* const* GetAcceptLanguageListForTesting(); +COMPONENT_EXPORT(UI_BASE) const char* const* GetAcceptLanguageListForTesting(); -UI_BASE_EXPORT size_t GetAcceptLanguageListSizeForTesting(); +COMPONENT_EXPORT(UI_BASE) size_t GetAcceptLanguageListSizeForTesting(); } // namespace l10n_util diff --git a/chromium/ui/base/l10n/l10n_util_android.h b/chromium/ui/base/l10n/l10n_util_android.h index 38592e9c58e..23fd7b1a937 100644 --- a/chromium/ui/base/l10n/l10n_util_android.h +++ b/chromium/ui/base/l10n/l10n_util_android.h @@ -9,16 +9,16 @@ #include +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace l10n_util { -UI_BASE_EXPORT base::string16 GetDisplayNameForLocale( - const std::string& locale, - const std::string& display_locale); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetDisplayNameForLocale(const std::string& locale, + const std::string& display_locale); -UI_BASE_EXPORT bool IsLayoutRtl(); +COMPONENT_EXPORT(UI_BASE) bool IsLayoutRtl(); } // namespace l10n_util diff --git a/chromium/ui/base/l10n/l10n_util_collator.h b/chromium/ui/base/l10n/l10n_util_collator.h index db3fa11481a..a6ac539ccfd 100644 --- a/chromium/ui/base/l10n/l10n_util_collator.h +++ b/chromium/ui/base/l10n/l10n_util_collator.h @@ -13,9 +13,9 @@ #include #include +#include "base/component_export.h" #include "base/i18n/string_compare.h" #include "third_party/icu/source/i18n/unicode/coll.h" -#include "ui/base/ui_base_export.h" namespace l10n_util { @@ -105,7 +105,8 @@ class StringComparator { // Specialization of operator() method for base::string16 version. template <> -UI_BASE_EXPORT inline bool StringComparator::operator()( +COMPONENT_EXPORT(UI_BASE) +inline bool StringComparator::operator()( const base::string16& lhs, const base::string16& rhs) const { // If we can not get collator instance for specified locale, just do simple diff --git a/chromium/ui/base/l10n/l10n_util_mac.h b/chromium/ui/base/l10n/l10n_util_mac.h index 9d7c42e19e4..0d9cb8683b3 100644 --- a/chromium/ui/base/l10n/l10n_util_mac.h +++ b/chromium/ui/base/l10n/l10n_util_mac.h @@ -10,8 +10,8 @@ #include #include +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" #ifdef __OBJC__ @class NSString; @@ -27,77 +27,88 @@ namespace l10n_util { // language and script by the - token and reformatted as // "$lowercase_language ($UPPERCASE_SCRIPT)". If the - token is not found, the // lowercase version of |locale| will be returned. -UI_BASE_EXPORT base::string16 GetDisplayNameForLocale( - const std::string& locale, - const std::string& display_locale); +COMPONENT_EXPORT(UI_BASE) +base::string16 GetDisplayNameForLocale(const std::string& locale, + const std::string& display_locale); // Remove the Windows-style accelerator marker (for labels, menuitems, etc.) // and change "..." into an ellipsis. // Returns the result in an autoreleased NSString. -UI_BASE_EXPORT NSString* FixUpWindowsStyleLabel(const base::string16& label); +COMPONENT_EXPORT(UI_BASE) +NSString* FixUpWindowsStyleLabel(const base::string16& label); // Pulls resource string from the string bundle and returns it. -UI_BASE_EXPORT NSString* GetNSString(int message_id); +COMPONENT_EXPORT(UI_BASE) NSString* GetNSString(int message_id); // Get a resource string and replace $1-$2-$3 with |a| and |b| // respectively. Additionally, $$ is replaced by $. -UI_BASE_EXPORT NSString* GetNSStringF(int message_id, const base::string16& a); -UI_BASE_EXPORT NSString* GetNSStringF(int message_id, - const base::string16& a, - const base::string16& b); -UI_BASE_EXPORT NSString* GetNSStringF(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c); -UI_BASE_EXPORT NSString* GetNSStringF(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c, - const base::string16& d); -UI_BASE_EXPORT NSString* GetNSStringF(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c, - const base::string16& d, - const base::string16& e); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringF(int message_id, const base::string16& a); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringF(int message_id, + const base::string16& a, + const base::string16& b); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringF(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringF(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c, + const base::string16& d); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringF(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c, + const base::string16& d, + const base::string16& e); // Variants that return the offset(s) of the replaced parameters. (See // app/l10n_util.h for more details.) -UI_BASE_EXPORT NSString* GetNSStringF(int message_id, - const base::string16& a, - const base::string16& b, - std::vector* offsets); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringF(int message_id, + const base::string16& a, + const base::string16& b, + std::vector* offsets); // Same as GetNSString, but runs the result through FixUpWindowsStyleLabel // before returning it. -UI_BASE_EXPORT NSString* GetNSStringWithFixup(int message_id); +COMPONENT_EXPORT(UI_BASE) NSString* GetNSStringWithFixup(int message_id); // Same as GetNSStringF, but runs the result through FixUpWindowsStyleLabel // before returning it. -UI_BASE_EXPORT NSString* GetNSStringFWithFixup(int message_id, - const base::string16& a); -UI_BASE_EXPORT NSString* GetNSStringFWithFixup(int message_id, - const base::string16& a, - const base::string16& b); -UI_BASE_EXPORT NSString* GetNSStringFWithFixup(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c); -UI_BASE_EXPORT NSString* GetNSStringFWithFixup(int message_id, - const base::string16& a, - const base::string16& b, - const base::string16& c, - const base::string16& d); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringFWithFixup(int message_id, const base::string16& a); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringFWithFixup(int message_id, + const base::string16& a, + const base::string16& b); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringFWithFixup(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c); +COMPONENT_EXPORT(UI_BASE) +NSString* GetNSStringFWithFixup(int message_id, + const base::string16& a, + const base::string16& b, + const base::string16& c, + const base::string16& d); // Get a resource string using |number| with a locale-specific plural rule. // |message_id| points to a message in the ICU syntax. // See http://userguide.icu-project.org/formatparse/messages and // go/plurals (Google internal). -UI_BASE_EXPORT NSString* GetPluralNSStringF(int message_id, int number); +COMPONENT_EXPORT(UI_BASE) +NSString* GetPluralNSStringF(int message_id, int number); // Support the override of the locale with the value from Cocoa. -UI_BASE_EXPORT void OverrideLocaleWithCocoaLocale(); -UI_BASE_EXPORT const std::string& GetLocaleOverride(); +COMPONENT_EXPORT(UI_BASE) void OverrideLocaleWithCocoaLocale(); +COMPONENT_EXPORT(UI_BASE) const std::string& GetLocaleOverride(); } // namespace l10n_util diff --git a/chromium/ui/base/l10n/l10n_util_win.h b/chromium/ui/base/l10n/l10n_util_win.h index a245ec91764..70a7be88046 100644 --- a/chromium/ui/base/l10n/l10n_util_win.h +++ b/chromium/ui/base/l10n/l10n_util_win.h @@ -9,8 +9,8 @@ #include #include +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace l10n_util { @@ -19,17 +19,17 @@ namespace l10n_util { // (e.g. WS_EX_LAYOUTRTL, WS_EX_RTLREADING, etc.) when creating a window. // Callers should OR this value into their extended style value when creating // a window. -UI_BASE_EXPORT int GetExtendedStyles(); +COMPONENT_EXPORT(UI_BASE) int GetExtendedStyles(); // TODO(xji): // This is a temporary name, it will eventually replace GetExtendedStyles -UI_BASE_EXPORT int GetExtendedTooltipStyles(); +COMPONENT_EXPORT(UI_BASE) int GetExtendedTooltipStyles(); // Give an HWND, this function sets the WS_EX_LAYOUTRTL extended style for the // underlying window. When this style is set, the UI for the window is going to // be mirrored. This is generally done for the UI of right-to-left languages // such as Hebrew. -UI_BASE_EXPORT void HWNDSetRTLLayout(HWND hwnd); +COMPONENT_EXPORT(UI_BASE) void HWNDSetRTLLayout(HWND hwnd); // See http://blogs.msdn.com/oldnewthing/archive/2005/09/15/467598.aspx // and http://blogs.msdn.com/oldnewthing/archive/2006/06/26/647365.aspx @@ -40,18 +40,18 @@ UI_BASE_EXPORT void HWNDSetRTLLayout(HWND hwnd); // override_font_family and font_size_scaler are not null, they'll be // filled with the font family name and the size scaler. The output // parameters are not modified if the return value is false. -UI_BASE_EXPORT bool NeedOverrideDefaultUIFont( - base::string16* override_font_family, - double* font_size_scaler); +COMPONENT_EXPORT(UI_BASE) +bool NeedOverrideDefaultUIFont(base::string16* override_font_family, + double* font_size_scaler); // Allow processes to override the configured locale with the user's Windows UI // languages. This function should generally be called once early in // Application startup. -UI_BASE_EXPORT void OverrideLocaleWithUILanguageList(); +COMPONENT_EXPORT(UI_BASE) void OverrideLocaleWithUILanguageList(); // Retrieve the locale override, or an empty vector if the locale has not been // or failed to be overridden. -UI_BASE_EXPORT const std::vector& GetLocaleOverrides(); +COMPONENT_EXPORT(UI_BASE) const std::vector& GetLocaleOverrides(); } // namespace l10n_util diff --git a/chromium/ui/base/l10n/time_format.cc b/chromium/ui/base/l10n/time_format.cc index c5a98fc850d..25b4336923f 100644 --- a/chromium/ui/base/l10n/time_format.cc +++ b/chromium/ui/base/l10n/time_format.cc @@ -7,6 +7,7 @@ #include #include "base/check_op.h" +#include "base/component_export.h" #include "base/lazy_instance.h" #include "base/notreached.h" #include "base/strings/string_util.h" @@ -14,7 +15,6 @@ #include "third_party/icu/source/common/unicode/unistr.h" #include "ui/base/l10n/formatter.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/ui_base_export.h" #include "ui/strings/grit/ui_strings.h" using base::TimeDelta; @@ -22,7 +22,8 @@ using ui::TimeFormat; namespace ui { -UI_BASE_EXPORT base::LazyInstance::Leaky g_container = +COMPONENT_EXPORT(UI_BASE) +base::LazyInstance::Leaky g_container = LAZY_INSTANCE_INITIALIZER; // static diff --git a/chromium/ui/base/l10n/time_format.h b/chromium/ui/base/l10n/time_format.h index 69617a66ddf..d1691441eb2 100644 --- a/chromium/ui/base/l10n/time_format.h +++ b/chromium/ui/base/l10n/time_format.h @@ -5,9 +5,9 @@ #ifndef UI_BASE_L10N_TIME_FORMAT_H_ #define UI_BASE_L10N_TIME_FORMAT_H_ +#include "base/component_export.h" #include "base/macros.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace base { class Time; @@ -17,7 +17,7 @@ class TimeDelta; namespace ui { // Methods to format time values as strings. -class UI_BASE_EXPORT TimeFormat { +class COMPONENT_EXPORT(UI_BASE) TimeFormat { public: enum Format { FORMAT_DURATION, // Plain duration, e.g. in English: "2 minutes". diff --git a/chromium/ui/base/layout.cc b/chromium/ui/base/layout.cc index fce80d356ce..d984586ceee 100644 --- a/chromium/ui/base/layout.cc +++ b/chromium/ui/base/layout.cc @@ -22,13 +22,13 @@ namespace ui { namespace { -std::vector* g_supported_scale_factors = NULL; +std::vector* g_supported_scale_factors = nullptr; } // namespace void SetSupportedScaleFactors( const std::vector& scale_factors) { - if (g_supported_scale_factors != NULL) + if (g_supported_scale_factors != nullptr) delete g_supported_scale_factors; g_supported_scale_factors = new std::vector(scale_factors); @@ -49,12 +49,12 @@ void SetSupportedScaleFactors( } const std::vector& GetSupportedScaleFactors() { - DCHECK(g_supported_scale_factors != NULL); + DCHECK(g_supported_scale_factors != nullptr); return *g_supported_scale_factors; } ScaleFactor GetSupportedScaleFactor(float scale) { - DCHECK(g_supported_scale_factors != NULL); + DCHECK(g_supported_scale_factors != nullptr); ScaleFactor closest_match = SCALE_FACTOR_100P; float smallest_diff = std::numeric_limits::max(); for (size_t i = 0; i < g_supported_scale_factors->size(); ++i) { @@ -85,7 +85,7 @@ ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors( original_scale_factors_ = new std::vector(*g_supported_scale_factors); } else { - original_scale_factors_ = NULL; + original_scale_factors_ = nullptr; } SetSupportedScaleFactors(new_scale_factors); } @@ -96,7 +96,7 @@ ScopedSetSupportedScaleFactors::~ScopedSetSupportedScaleFactors() { delete original_scale_factors_; } else { delete g_supported_scale_factors; - g_supported_scale_factors = NULL; + g_supported_scale_factors = nullptr; } } diff --git a/chromium/ui/base/layout.h b/chromium/ui/base/layout.h index fd2627bbc50..e25289b3a48 100644 --- a/chromium/ui/base/layout.h +++ b/chromium/ui/base/layout.h @@ -7,10 +7,10 @@ #include +#include "base/component_export.h" #include "base/macros.h" #include "build/build_config.h" #include "ui/base/resource/scale_factor.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/native_widget_types.h" namespace ui { @@ -18,29 +18,32 @@ namespace ui { // Changes the value of GetSupportedScaleFactors() to |scale_factors|. // Use ScopedSetSupportedScaleFactors for unit tests as not to affect the // state of other tests. -UI_BASE_EXPORT void SetSupportedScaleFactors( - const std::vector& scale_factors); +COMPONENT_EXPORT(UI_BASE) +void SetSupportedScaleFactors(const std::vector& scale_factors); // Returns a vector with the scale factors which are supported by this // platform, in ascending order. -UI_BASE_EXPORT const std::vector& GetSupportedScaleFactors(); +COMPONENT_EXPORT(UI_BASE) +const std::vector& GetSupportedScaleFactors(); // Returns the supported ScaleFactor which most closely matches |scale|. // Converting from float to ScaleFactor is inefficient and should be done as // little as possible. -UI_BASE_EXPORT ScaleFactor GetSupportedScaleFactor(float image_scale); +COMPONENT_EXPORT(UI_BASE) +ScaleFactor GetSupportedScaleFactor(float image_scale); // Returns the ScaleFactor used by |view|. -UI_BASE_EXPORT float GetScaleFactorForNativeView(gfx::NativeView view); +COMPONENT_EXPORT(UI_BASE) +float GetScaleFactorForNativeView(gfx::NativeView view); // Returns true if the scale passed in is the list of supported scales for // the platform. -UI_BASE_EXPORT bool IsSupportedScale(float scale); +COMPONENT_EXPORT(UI_BASE) bool IsSupportedScale(float scale); namespace test { // Class which changes the value of GetSupportedScaleFactors() to // |new_scale_factors| for the duration of its lifetime. -class UI_BASE_EXPORT ScopedSetSupportedScaleFactors { +class COMPONENT_EXPORT(UI_BASE) ScopedSetSupportedScaleFactors { public: explicit ScopedSetSupportedScaleFactors( const std::vector& new_scale_factors); diff --git a/chromium/ui/base/models/button_menu_item_model.h b/chromium/ui/base/models/button_menu_item_model.h index eabf45695aa..7772052fda8 100644 --- a/chromium/ui/base/models/button_menu_item_model.h +++ b/chromium/ui/base/models/button_menu_item_model.h @@ -8,16 +8,16 @@ #include #include "base/compiler_specific.h" +#include "base/component_export.h" #include "base/macros.h" #include "base/strings/string16.h" #include "ui/base/accelerators/accelerator.h" -#include "ui/base/ui_base_export.h" namespace ui { // A model representing the rows of buttons that should be inserted in a button // containing menu item. -class UI_BASE_EXPORT ButtonMenuItemModel { +class COMPONENT_EXPORT(UI_BASE) ButtonMenuItemModel { public: // Types of buttons. enum ButtonType { @@ -26,7 +26,7 @@ class UI_BASE_EXPORT ButtonMenuItemModel { TYPE_BUTTON_LABEL }; - class UI_BASE_EXPORT Delegate : public AcceleratorProvider { + class COMPONENT_EXPORT(UI_BASE) Delegate : public AcceleratorProvider { public: // Some command ids have labels that change over time. virtual bool IsItemForCommandIdDynamic(int command_id) const; diff --git a/chromium/ui/base/models/combobox_model.cc b/chromium/ui/base/models/combobox_model.cc index c6913da55e5..a6a311fc465 100644 --- a/chromium/ui/base/models/combobox_model.cc +++ b/chromium/ui/base/models/combobox_model.cc @@ -4,9 +4,27 @@ #include "ui/base/models/combobox_model.h" +#include "ui/base/models/image_model.h" + namespace ui { -bool ComboboxModel::IsItemSeparatorAt(int index) { +base::string16 ComboboxModel::GetDropDownTextAt(int index) const { + return GetItemAt(index); +} + +base::string16 ComboboxModel::GetDropDownSecondaryTextAt(int index) const { + return base::string16(); +} + +ImageModel ComboboxModel::GetIconAt(int index) const { + return ui::ImageModel(); +} + +ImageModel ComboboxModel::GetDropDownIconAt(int index) const { + return GetIconAt(index); +} + +bool ComboboxModel::IsItemSeparatorAt(int index) const { return false; } diff --git a/chromium/ui/base/models/combobox_model.h b/chromium/ui/base/models/combobox_model.h index 2fcd7b69029..994ac2bbef7 100644 --- a/chromium/ui/base/models/combobox_model.h +++ b/chromium/ui/base/models/combobox_model.h @@ -5,15 +5,16 @@ #ifndef UI_BASE_MODELS_COMBOBOX_MODEL_H_ #define UI_BASE_MODELS_COMBOBOX_MODEL_H_ +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace ui { class ComboboxModelObserver; +class ImageModel; // A data model for a combo box. -class UI_BASE_EXPORT ComboboxModel { +class COMPONENT_EXPORT(UI_BASE) ComboboxModel { public: virtual ~ComboboxModel() {} @@ -21,11 +22,27 @@ class UI_BASE_EXPORT ComboboxModel { virtual int GetItemCount() const = 0; // Returns the string at the specified index. - virtual base::string16 GetItemAt(int index) = 0; + virtual base::string16 GetItemAt(int index) const = 0; + + // Returns the string to be shown in the dropdown for the item at |index|. By + // default, it returns GetItemAt(index). + virtual base::string16 GetDropDownTextAt(int index) const; + + // Returns the secondary string at the specified index. Secondary strings are + // displayed in a second line inside every menu item. + virtual base::string16 GetDropDownSecondaryTextAt(int index) const; + + // Gets the icon for the item at the specified index. ImageModel is empty if + // there is no icon. + virtual ImageModel GetIconAt(int index) const; + + // Gets the icon for the item at |index|. ImageModel is empty if there is no + // icon. By default, it returns GetIconAt(index). + virtual ImageModel GetDropDownIconAt(int index) const; // Should return true if the item at |index| is a non-selectable separator // item. - virtual bool IsItemSeparatorAt(int index); + virtual bool IsItemSeparatorAt(int index) const; // The index of the item that is selected by default (before user // interaction). diff --git a/chromium/ui/base/models/combobox_model_observer.h b/chromium/ui/base/models/combobox_model_observer.h index 42d15bdc0e0..5e00ab68a0c 100644 --- a/chromium/ui/base/models/combobox_model_observer.h +++ b/chromium/ui/base/models/combobox_model_observer.h @@ -5,15 +5,16 @@ #ifndef UI_BASE_MODELS_COMBOBOX_MODEL_OBSERVER_H_ #define UI_BASE_MODELS_COMBOBOX_MODEL_OBSERVER_H_ +#include "base/component_export.h" #include "base/observer_list_types.h" -#include "ui/base/ui_base_export.h" namespace ui { class ComboboxModel; // Observer for the ComboboxModel. -class UI_BASE_EXPORT ComboboxModelObserver : public base::CheckedObserver { +class COMPONENT_EXPORT(UI_BASE) ComboboxModelObserver + : public base::CheckedObserver { public: // Invoked when |model| has changed in some way. The observer should assume // everything changed. diff --git a/chromium/ui/base/models/image_model.cc b/chromium/ui/base/models/image_model.cc index 501f8dc9495..9578759666b 100644 --- a/chromium/ui/base/models/image_model.cc +++ b/chromium/ui/base/models/image_model.cc @@ -84,6 +84,14 @@ bool ImageModel::IsImage() const { return image_ && !image_.value().IsEmpty(); } +gfx::Size ImageModel::Size() const { + if (IsVectorIcon()) { + const int icon_size = GetVectorIcon().icon_size(); + return gfx::Size(icon_size, icon_size); + } + return IsImage() ? GetImage().Size() : gfx::Size(); +} + const VectorIconModel ImageModel::GetVectorIcon() const { DCHECK(IsVectorIcon()); return vector_icon_model_.value(); diff --git a/chromium/ui/base/models/image_model.h b/chromium/ui/base/models/image_model.h index 098a92ed42d..dbc4cf8b01d 100644 --- a/chromium/ui/base/models/image_model.h +++ b/chromium/ui/base/models/image_model.h @@ -6,9 +6,9 @@ #define UI_BASE_MODELS_IMAGE_MODEL_H_ #include "base/callback.h" +#include "base/component_export.h" #include "base/optional.h" #include "third_party/skia/include/core/SkColor.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" @@ -28,7 +28,7 @@ namespace ui { // is only used internal to ImageModel and should never be instantiated except // by ImageModel. -class UI_BASE_EXPORT VectorIconModel { +class COMPONENT_EXPORT(UI_BASE) VectorIconModel { public: VectorIconModel(); VectorIconModel(const VectorIconModel&); @@ -71,7 +71,7 @@ class UI_BASE_EXPORT VectorIconModel { // of the two may be specified at a given time. This class is instantiated via // the FromXXXX static factory functions. -class UI_BASE_EXPORT ImageModel { +class COMPONENT_EXPORT(UI_BASE) ImageModel { public: ImageModel(); ImageModel(const ImageModel&); @@ -92,6 +92,7 @@ class UI_BASE_EXPORT ImageModel { bool IsEmpty() const; bool IsVectorIcon() const; bool IsImage() const; + gfx::Size Size() const; // Only valid if IsVectorIcon() or IsImage() return true, respectively. const VectorIconModel GetVectorIcon() const; const gfx::Image GetImage() const; diff --git a/chromium/ui/base/models/image_model_unittest.cc b/chromium/ui/base/models/image_model_unittest.cc index 3b494797afc..8bb31fc06a1 100644 --- a/chromium/ui/base/models/image_model_unittest.cc +++ b/chromium/ui/base/models/image_model_unittest.cc @@ -54,6 +54,14 @@ TEST(ImageModelTest, CheckForImage) { EXPECT_TRUE(image_model.IsImage()); } +TEST(ImageModelTest, Size) { + EXPECT_EQ(gfx::Size(), ImageModel().Size()); + EXPECT_EQ(gfx::Size(16, 16), + ImageModel::FromVectorIcon(GetVectorIcon(), -1, 16).Size()); + EXPECT_EQ(gfx::Size(16, 16), + ImageModel::FromImage(gfx::test::CreateImage(16, 16)).Size()); +} + TEST(ImageModelTest, CheckAssignVectorIcon) { VectorIconModel vector_icon_model_dest; VectorIconModel vector_icon_model_src = diff --git a/chromium/ui/base/models/list_model.h b/chromium/ui/base/models/list_model.h index 3187ee5fd86..ed5217d99d9 100644 --- a/chromium/ui/base/models/list_model.h +++ b/chromium/ui/base/models/list_model.h @@ -11,7 +11,7 @@ #include #include -#include "base/logging.h" +#include "base/check_op.h" #include "base/macros.h" #include "base/observer_list.h" #include "ui/base/models/list_model_observer.h" diff --git a/chromium/ui/base/models/list_model_observer.h b/chromium/ui/base/models/list_model_observer.h index cc8be0f6e0a..c7d42310504 100644 --- a/chromium/ui/base/models/list_model_observer.h +++ b/chromium/ui/base/models/list_model_observer.h @@ -7,11 +7,11 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { -class UI_BASE_EXPORT ListModelObserver { +class COMPONENT_EXPORT(UI_BASE) ListModelObserver { public: // Invoked after items has been added to the model. virtual void ListItemsAdded(size_t start, size_t count) = 0; diff --git a/chromium/ui/base/models/list_selection_model.h b/chromium/ui/base/models/list_selection_model.h index e4e25150351..4c98ae9f645 100644 --- a/chromium/ui/base/models/list_selection_model.h +++ b/chromium/ui/base/models/list_selection_model.h @@ -9,7 +9,7 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -25,7 +25,7 @@ namespace ui { // // Typically there is only one selected item, in which case the anchor and // active index correspond to the same thing. -class UI_BASE_EXPORT ListSelectionModel { +class COMPONENT_EXPORT(UI_BASE) ListSelectionModel { public: using SelectedIndices = std::vector; diff --git a/chromium/ui/base/models/menu_model.cc b/chromium/ui/base/models/menu_model.cc index 90a350cf9ce..32070758287 100644 --- a/chromium/ui/base/models/menu_model.cc +++ b/chromium/ui/base/models/menu_model.cc @@ -19,6 +19,14 @@ bool MenuModel::IsVisibleAt(int index) const { return true; } +bool MenuModel::IsAlertedAt(int index) const { + return false; +} + +bool MenuModel::IsNewFeatureAt(int index) const { + return false; +} + // static bool MenuModel::GetModelAndIndexForCommandId(int command_id, MenuModel** model, @@ -52,6 +60,10 @@ base::string16 MenuModel::GetMinorTextAt(int index) const { return base::string16(); } +base::string16 MenuModel::GetSecondaryLabelAt(int index) const { + return base::string16(); +} + ImageModel MenuModel::GetMinorIconAt(int index) const { return ImageModel(); } diff --git a/chromium/ui/base/models/menu_model.h b/chromium/ui/base/models/menu_model.h index 887eee64e27..c746b37d627 100644 --- a/chromium/ui/base/models/menu_model.h +++ b/chromium/ui/base/models/menu_model.h @@ -5,11 +5,11 @@ #ifndef UI_BASE_MODELS_MENU_MODEL_H_ #define UI_BASE_MODELS_MENU_MODEL_H_ +#include "base/component_export.h" #include "base/memory/weak_ptr.h" #include "base/strings/string16.h" #include "ui/base/models/menu_model_delegate.h" #include "ui/base/models/menu_separator_types.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/native_widget_types.h" namespace gfx { @@ -23,7 +23,8 @@ class ButtonMenuItemModel; class ImageModel; // An interface implemented by an object that provides the content of a menu. -class UI_BASE_EXPORT MenuModel : public base::SupportsWeakPtr { +class COMPONENT_EXPORT(UI_BASE) MenuModel + : public base::SupportsWeakPtr { public: // The type of item. enum ItemType { @@ -65,6 +66,10 @@ class UI_BASE_EXPORT MenuModel : public base::SupportsWeakPtr { // Returns the label of the item at the specified index. virtual base::string16 GetLabelAt(int index) const = 0; + // Returns the secondary label of the item at the specified index. Secondary + // label is shown below the label. + virtual base::string16 GetSecondaryLabelAt(int index) const; + // Returns the minor text of the item at the specified index. The minor text // is rendered to the right of the label and using the font GetLabelFontAt(). virtual base::string16 GetMinorTextAt(int index) const; @@ -108,6 +113,15 @@ class UI_BASE_EXPORT MenuModel : public base::SupportsWeakPtr { // Returns true if the menu item is visible. virtual bool IsVisibleAt(int index) const; + // Returns true if the item is rendered specially to draw attention + // for in-product help. + virtual bool IsAlertedAt(int index) const; + + // Returns true if the menu item grants access to a new feature that we want + // to show off to users (items marked as new will receive a "New" badge when + // the appropriate flag is enabled). + virtual bool IsNewFeatureAt(int index) const; + // Returns the model for the submenu at the specified index. virtual MenuModel* GetSubmenuModelAt(int index) const = 0; diff --git a/chromium/ui/base/models/simple_combobox_model.cc b/chromium/ui/base/models/simple_combobox_model.cc index ff4f04f8036..64e05588544 100644 --- a/chromium/ui/base/models/simple_combobox_model.cc +++ b/chromium/ui/base/models/simple_combobox_model.cc @@ -18,11 +18,11 @@ int SimpleComboboxModel::GetItemCount() const { return items_.size(); } -base::string16 SimpleComboboxModel::GetItemAt(int index) { +base::string16 SimpleComboboxModel::GetItemAt(int index) const { return items_[index]; } -bool SimpleComboboxModel::IsItemSeparatorAt(int index) { +bool SimpleComboboxModel::IsItemSeparatorAt(int index) const { return items_[index].empty(); } diff --git a/chromium/ui/base/models/simple_combobox_model.h b/chromium/ui/base/models/simple_combobox_model.h index a50373a5cf5..140760a604b 100644 --- a/chromium/ui/base/models/simple_combobox_model.h +++ b/chromium/ui/base/models/simple_combobox_model.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_MODELS_SIMPLE_COMBOBOX_MODEL_H_ #define UI_BASE_MODELS_SIMPLE_COMBOBOX_MODEL_H_ +#include "base/component_export.h" #include "base/macros.h" #include "ui/base/models/combobox_model.h" @@ -14,15 +15,15 @@ namespace ui { // A simple data model for a combobox that takes a string16 vector as the items. // An empty string will be a separator. -class UI_BASE_EXPORT SimpleComboboxModel : public ComboboxModel { +class COMPONENT_EXPORT(UI_BASE) SimpleComboboxModel : public ComboboxModel { public: explicit SimpleComboboxModel(std::vector items); ~SimpleComboboxModel() override; // ui::ComboboxModel: int GetItemCount() const override; - base::string16 GetItemAt(int index) override; - bool IsItemSeparatorAt(int index) override; + base::string16 GetItemAt(int index) const override; + bool IsItemSeparatorAt(int index) const override; int GetDefaultIndex() const override; private: diff --git a/chromium/ui/base/models/simple_menu_model.cc b/chromium/ui/base/models/simple_menu_model.cc index 88053e9d501..0c37f6e2cae 100644 --- a/chromium/ui/base/models/simple_menu_model.cc +++ b/chromium/ui/base/models/simple_menu_model.cc @@ -39,6 +39,10 @@ bool SimpleMenuModel::Delegate::IsCommandIdVisible(int command_id) const { return true; } +bool SimpleMenuModel::Delegate::IsCommandIdAlerted(int command_id) const { + return false; +} + bool SimpleMenuModel::Delegate::IsItemForCommandIdDynamic( int command_id) const { return false; @@ -317,6 +321,10 @@ void SimpleMenuModel::SetVisibleAt(int index, bool visible) { MenuItemsChanged(); } +void SimpleMenuModel::SetIsNewFeatureAt(int index, bool is_new_feature) { + items_[ValidateItemIndex(index)].is_new_feature = is_new_feature; +} + void SimpleMenuModel::Clear() { items_.clear(); MenuItemsChanged(); @@ -432,6 +440,18 @@ bool SimpleMenuModel::IsVisibleAt(int index) const { items_[ValidateItemIndex(index)].visible; } +bool SimpleMenuModel::IsAlertedAt(int index) const { + const int command_id = GetCommandIdAt(index); + if (!delegate_ || command_id == kSeparatorId || command_id == kTitleId) + return false; + + return delegate_->IsCommandIdAlerted(command_id); +} + +bool SimpleMenuModel::IsNewFeatureAt(int index) const { + return items_[ValidateItemIndex(index)].is_new_feature; +} + void SimpleMenuModel::ActivatedAt(int index) { ActivatedAt(index, 0); } diff --git a/chromium/ui/base/models/simple_menu_model.h b/chromium/ui/base/models/simple_menu_model.h index 2b06f3f4a03..5f1116ba19b 100644 --- a/chromium/ui/base/models/simple_menu_model.h +++ b/chromium/ui/base/models/simple_menu_model.h @@ -9,6 +9,7 @@ #include #include "base/compiler_specific.h" +#include "base/component_export.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/strings/string16.h" @@ -24,9 +25,9 @@ class ButtonMenuItemModel; // items. This makes it easy to construct fixed menus. Menus populated by // dynamic data sources may be better off implementing MenuModel directly. // The breadth of MenuModel is not exposed through this API. -class UI_BASE_EXPORT SimpleMenuModel : public MenuModel { +class COMPONENT_EXPORT(UI_BASE) SimpleMenuModel : public MenuModel { public: - class UI_BASE_EXPORT Delegate : public AcceleratorProvider { + class COMPONENT_EXPORT(UI_BASE) Delegate : public AcceleratorProvider { public: ~Delegate() override {} @@ -40,6 +41,10 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel { // Delegate should return true if |command_id| should be visible. virtual bool IsCommandIdVisible(int command_id) const; + // Determines if |command_id| should be rendered with an alert for + // in-product help. + virtual bool IsCommandIdAlerted(int command_id) const; + // Some command ids have labels and icons that change over time. virtual bool IsItemForCommandIdDynamic(int command_id) const; virtual base::string16 GetLabelForCommandId(int command_id) const; @@ -158,6 +163,9 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel { // Sets whether the item at |index| is visible. void SetVisibleAt(int index, bool visible); + // Sets whether the item at |index| is new. + void SetIsNewFeatureAt(int index, bool is_new_feature); + // Clears all items. Note that it does not free MenuModel of submenu. void Clear(); @@ -182,6 +190,8 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel { ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const override; bool IsEnabledAt(int index) const override; bool IsVisibleAt(int index) const override; + bool IsAlertedAt(int index) const override; + bool IsNewFeatureAt(int index) const override; void ActivatedAt(int index) override; void ActivatedAt(int index, int event_flags) override; MenuModel* GetSubmenuModelAt(int index) const override; @@ -215,6 +225,7 @@ class UI_BASE_EXPORT SimpleMenuModel : public MenuModel { MenuSeparatorType separator_type = NORMAL_SEPARATOR; bool enabled = true; bool visible = true; + bool is_new_feature = false; }; typedef std::vector ItemVector; diff --git a/chromium/ui/base/models/simple_menu_model_unittest.cc b/chromium/ui/base/models/simple_menu_model_unittest.cc index 4fe768d11b9..b38debbc855 100644 --- a/chromium/ui/base/models/simple_menu_model_unittest.cc +++ b/chromium/ui/base/models/simple_menu_model_unittest.cc @@ -16,6 +16,8 @@ namespace ui { namespace { +constexpr int kAlertedCommandId = 2; + class DelegateBase : public SimpleMenuModel::Delegate { public: DelegateBase() : SimpleMenuModel::Delegate() {} @@ -37,6 +39,10 @@ class DelegateBase : public SimpleMenuModel::Delegate { return command_id < 100; } + bool IsCommandIdAlerted(int command_id) const override { + return command_id == kAlertedCommandId; + } + void ExecuteCommand(int command_id, int event_flags) override {} bool IsItemForCommandIdDynamic(int command_id) const override { @@ -147,6 +153,32 @@ TEST(SimpleMenuModelTest, IsVisibleAtWithDelegateAndCommandNotVisible) { ASSERT_FALSE(simple_menu_model.IsEnabledAt(0)); } +TEST(SimpleMenuModelTest, IsAlertedAtViaDelegate) { + DelegateBase delegate; + SimpleMenuModel simple_menu_model(&delegate); + simple_menu_model.AddItem(kAlertedCommandId, + base::ASCIIToUTF16("alerted item")); + simple_menu_model.AddItem(kAlertedCommandId + 1, + base::ASCIIToUTF16("non-alerted item")); + + EXPECT_TRUE(simple_menu_model.IsAlertedAt(0)); + EXPECT_FALSE(simple_menu_model.IsAlertedAt(1)); +} + +TEST(SimpleMenuModelTest, SetIsNewFeatureAt) { + SimpleMenuModel simple_menu_model(nullptr); + simple_menu_model.AddItem(/*command_id*/ 5, + base::ASCIIToUTF16("menu item 0")); + simple_menu_model.AddItem(/*command_id*/ 6, + base::ASCIIToUTF16("menu item 1")); + + simple_menu_model.SetIsNewFeatureAt(/*index*/ 0, false); + simple_menu_model.SetIsNewFeatureAt(/*index*/ 1, true); + + ASSERT_FALSE(simple_menu_model.IsNewFeatureAt(0)); + ASSERT_TRUE(simple_menu_model.IsNewFeatureAt(1)); +} + TEST(SimpleMenuModelTest, HasIconsViaDelegate) { DelegateBase delegate; SimpleMenuModel simple_menu_model(&delegate); diff --git a/chromium/ui/base/models/table_model.h b/chromium/ui/base/models/table_model.h index 088cda5a42d..6e098fbe8dc 100644 --- a/chromium/ui/base/models/table_model.h +++ b/chromium/ui/base/models/table_model.h @@ -7,9 +7,9 @@ #include +#include "base/component_export.h" #include "base/strings/string16.h" #include "third_party/icu/source/i18n/unicode/coll.h" -#include "ui/base/ui_base_export.h" namespace gfx { class ImageSkia; @@ -20,7 +20,7 @@ namespace ui { class TableModelObserver; // The model driving the TableView. -class UI_BASE_EXPORT TableModel { +class COMPONENT_EXPORT(UI_BASE) TableModel { public: // Size of the table row icon, if used. static constexpr int kIconSize = 16; @@ -65,7 +65,7 @@ class UI_BASE_EXPORT TableModel { }; // TableColumn specifies the title, alignment and size of a particular column. -struct UI_BASE_EXPORT TableColumn { +struct COMPONENT_EXPORT(UI_BASE) TableColumn { enum Alignment { LEFT, RIGHT, CENTER }; diff --git a/chromium/ui/base/models/table_model_observer.h b/chromium/ui/base/models/table_model_observer.h index 20b5c7f0e13..eaff0750819 100644 --- a/chromium/ui/base/models/table_model_observer.h +++ b/chromium/ui/base/models/table_model_observer.h @@ -5,13 +5,13 @@ #ifndef UI_BASE_MODELS_TABLE_MODEL_OBSERVER_H_ #define UI_BASE_MODELS_TABLE_MODEL_OBSERVER_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { // Observer for a TableModel. Anytime the model changes, it must notify its // observer. -class UI_BASE_EXPORT TableModelObserver { +class COMPONENT_EXPORT(UI_BASE) TableModelObserver { public: // Invoked when the model has been completely changed. virtual void OnModelChanged() = 0; diff --git a/chromium/ui/base/models/tree_model.h b/chromium/ui/base/models/tree_model.h index 815cebbdea9..20dc6cdef24 100644 --- a/chromium/ui/base/models/tree_model.h +++ b/chromium/ui/base/models/tree_model.h @@ -7,8 +7,8 @@ #include +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace gfx { class ImageSkia; @@ -34,7 +34,7 @@ class TreeModelNode { }; // Observer for the TreeModel. Notified of significant events to the model. -class UI_BASE_EXPORT TreeModelObserver { +class COMPONENT_EXPORT(UI_BASE) TreeModelObserver { public: // Notification that nodes were added to the specified parent. virtual void TreeNodesAdded(TreeModel* model, @@ -61,7 +61,7 @@ class UI_BASE_EXPORT TreeModelObserver { // of bookkeeping for the tree to be implemented. Generally you will want to // use TreeNodeModel which provides a standard implementation for basic // hierarchy and observer notification. See tree_node_model.h. -class UI_BASE_EXPORT TreeModel { +class COMPONENT_EXPORT(UI_BASE) TreeModel { public: using Nodes = std::vector; diff --git a/chromium/ui/base/models/tree_node_iterator.h b/chromium/ui/base/models/tree_node_iterator.h index 4f84b20e2b9..931e2606e0d 100644 --- a/chromium/ui/base/models/tree_node_iterator.h +++ b/chromium/ui/base/models/tree_node_iterator.h @@ -6,8 +6,8 @@ #define UI_BASE_MODELS_TREE_NODE_ITERATOR_H_ #include "base/callback.h" +#include "base/check.h" #include "base/containers/stack.h" -#include "base/logging.h" #include "base/macros.h" namespace ui { diff --git a/chromium/ui/base/models/tree_node_model.h b/chromium/ui/base/models/tree_node_model.h index b1213ba67a5..d21bf9a66d0 100644 --- a/chromium/ui/base/models/tree_node_model.h +++ b/chromium/ui/base/models/tree_node_model.h @@ -11,7 +11,7 @@ #include #include -#include "base/logging.h" +#include "base/check_op.h" #include "base/macros.h" #include "base/observer_list.h" #include "base/strings/string16.h" diff --git a/chromium/ui/base/mojom/BUILD.gn b/chromium/ui/base/mojom/BUILD.gn index 8b330d88d52..49ea535072d 100644 --- a/chromium/ui/base/mojom/BUILD.gn +++ b/chromium/ui/base/mojom/BUILD.gn @@ -10,6 +10,15 @@ mojom("mojom") { "ui_base_types.mojom", "window_open_disposition.mojom", ] + + if (is_mac) { + sources += [ "attributed_string.mojom" ] + public_deps = [ + "//mojo/public/mojom/base", + "//ui/gfx/range/mojom", + ] + } + cpp_typemaps = [ { types = [ diff --git a/chromium/ui/base/mojom/attributed_string.mojom b/chromium/ui/base/mojom/attributed_string.mojom new file mode 100644 index 00000000000..18969f51079 --- /dev/null +++ b/chromium/ui/base/mojom/attributed_string.mojom @@ -0,0 +1,32 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module ui.mojom; + +import "mojo/public/mojom/base/string16.mojom"; +import "ui/gfx/range/mojom/range.mojom"; + +// This will serialize the font information of an NSAttributedString so that +// it can be sent over mojo. This only stores the information of the +// NSFontAttributeName. The motive is that of security: using NSArchiver and +// friends to send objects from the renderer to the browser could lead to +// deserialization of arbitrary objects. This restricts serialization to a +// specific object class and specific attributes of that object. + +// A C++ mojo-friendly representation of the NSFontAttributeName attribute +// set. +struct FontAttribute { + mojo_base.mojom.String16 font_name; + float font_point_size; + gfx.mojom.Range effective_range; +}; + +// A struct that contains the pertinent information from an NSAttributedString, +// which can be serialized over mojo. +struct AttributedString { + // The plain-text string. + mojo_base.mojom.String16 string; + // The set of attributes that style |string|. + array attributes; +}; diff --git a/chromium/ui/base/mojom/window_open_disposition_mojom_traits.h b/chromium/ui/base/mojom/window_open_disposition_mojom_traits.h index 84b7c86f102..a9862b8d62d 100644 --- a/chromium/ui/base/mojom/window_open_disposition_mojom_traits.h +++ b/chromium/ui/base/mojom/window_open_disposition_mojom_traits.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_MOJOM_WINDOW_OPEN_DISPOSITION_MOJOM_TRAITS_H_ #define UI_BASE_MOJOM_WINDOW_OPEN_DISPOSITION_MOJOM_TRAITS_H_ -#include "base/logging.h" +#include "base/notreached.h" #include "mojo/public/cpp/bindings/enum_traits.h" #include "ui/base/mojom/window_open_disposition.mojom.h" #include "ui/base/window_open_disposition.h" diff --git a/chromium/ui/base/nine_image_painter_factory.h b/chromium/ui/base/nine_image_painter_factory.h index af4b13c3dbb..dd4e7052952 100644 --- a/chromium/ui/base/nine_image_painter_factory.h +++ b/chromium/ui/base/nine_image_painter_factory.h @@ -7,7 +7,7 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" // A macro to define arrays of IDR constants used with CreateImageGridPainter. #define IMAGE_GRID(x) { x ## _TOP_LEFT, x ## _TOP, x ## _TOP_RIGHT, \ @@ -44,7 +44,8 @@ namespace ui { // Creates a NineImagePainter from an array of image ids. It's expected the // array came from the IMAGE_GRID macro. -UI_BASE_EXPORT std::unique_ptr CreateNineImagePainter( +COMPONENT_EXPORT(UI_BASE) +std::unique_ptr CreateNineImagePainter( const int image_ids[]); } // namespace ui diff --git a/chromium/ui/base/page_transition_types.h b/chromium/ui/base/page_transition_types.h index 21773ad6241..ea8632c706e 100644 --- a/chromium/ui/base/page_transition_types.h +++ b/chromium/ui/base/page_transition_types.h @@ -7,7 +7,7 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -150,43 +150,47 @@ enum PageTransition { // Compares two PageTransition types ignoring qualifiers. |rhs| is taken to // be a compile time constant, and hence must not contain any qualifiers. -UI_BASE_EXPORT bool PageTransitionCoreTypeIs(PageTransition lhs, - PageTransition rhs); +COMPONENT_EXPORT(UI_BASE) +bool PageTransitionCoreTypeIs(PageTransition lhs, PageTransition rhs); // Compares two PageTransition types including qualifiers. Rarely useful, // PageTransitionCoreTypeIs() is more likely what you need. -UI_BASE_EXPORT bool PageTransitionTypeIncludingQualifiersIs(PageTransition lhs, - PageTransition rhs); +COMPONENT_EXPORT(UI_BASE) +bool PageTransitionTypeIncludingQualifiersIs(PageTransition lhs, + PageTransition rhs); // Simplifies the provided transition by removing any qualifier -UI_BASE_EXPORT PageTransition PageTransitionStripQualifier( - PageTransition type); +COMPONENT_EXPORT(UI_BASE) +PageTransition PageTransitionStripQualifier(PageTransition type); -UI_BASE_EXPORT bool PageTransitionIsValidType(int32_t type); +COMPONENT_EXPORT(UI_BASE) bool PageTransitionIsValidType(int32_t type); -UI_BASE_EXPORT PageTransition PageTransitionFromInt(int32_t type); +COMPONENT_EXPORT(UI_BASE) PageTransition PageTransitionFromInt(int32_t type); // Returns true if the given transition is a top-level frame transition, or // false if the transition was for a subframe. -UI_BASE_EXPORT bool PageTransitionIsMainFrame(PageTransition type); +COMPONENT_EXPORT(UI_BASE) bool PageTransitionIsMainFrame(PageTransition type); // Returns whether a transition involves a redirection -UI_BASE_EXPORT bool PageTransitionIsRedirect(PageTransition type); +COMPONENT_EXPORT(UI_BASE) bool PageTransitionIsRedirect(PageTransition type); // Returns whether a transition is a new navigation (rather than a return // to a previously committed navigation). -UI_BASE_EXPORT bool PageTransitionIsNewNavigation(PageTransition type); +COMPONENT_EXPORT(UI_BASE) +bool PageTransitionIsNewNavigation(PageTransition type); // Return the qualifier -UI_BASE_EXPORT int32_t PageTransitionGetQualifier(PageTransition type); +COMPONENT_EXPORT(UI_BASE) +int32_t PageTransitionGetQualifier(PageTransition type); // Returns true if the transition can be triggered by the web instead of // through UI or similar. -UI_BASE_EXPORT bool PageTransitionIsWebTriggerable(PageTransition type); +COMPONENT_EXPORT(UI_BASE) +bool PageTransitionIsWebTriggerable(PageTransition type); // Return a string version of the core type values. -UI_BASE_EXPORT const char* PageTransitionGetCoreTransitionString( - PageTransition type); +COMPONENT_EXPORT(UI_BASE) +const char* PageTransitionGetCoreTransitionString(PageTransition type); // Declare a dummy class that is intentionally never defined. class DontUseOperatorEquals; diff --git a/chromium/ui/base/pointer/pointer_device.h b/chromium/ui/base/pointer/pointer_device.h index 19765542fb3..c50fdde7fe7 100644 --- a/chromium/ui/base/pointer/pointer_device.h +++ b/chromium/ui/base/pointer/pointer_device.h @@ -7,8 +7,8 @@ #include +#include "base/component_export.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" #if defined(OS_ANDROID) #include @@ -22,7 +22,8 @@ enum class TouchScreensAvailability { DISABLED, // Touch screens are present and disabled. }; -UI_BASE_EXPORT TouchScreensAvailability GetTouchScreensAvailability(); +COMPONENT_EXPORT(UI_BASE) +TouchScreensAvailability GetTouchScreensAvailability(); // Returns the maximum number of simultaneous touch contacts supported // by the device. In the case of devices with multiple digitizers (e.g. @@ -31,7 +32,7 @@ UI_BASE_EXPORT TouchScreensAvailability GetTouchScreensAvailability(); // For example, suppose a device has 3 touchscreens, which support 2, 5, // and 10 simultaneous touch contacts, respectively. This returns 10. // http://www.w3.org/TR/pointerevents/#widl-Navigator-maxTouchPoints -UI_BASE_EXPORT int MaxTouchPoints(); +COMPONENT_EXPORT(UI_BASE) int MaxTouchPoints(); // Bit field values indicating available pointer types. Identical to // blink::PointerType enums, enforced by compile-time assertions in @@ -60,12 +61,15 @@ enum HoverType { int GetAvailablePointerTypes(); int GetAvailableHoverTypes(); -UI_BASE_EXPORT std::pair GetAvailablePointerAndHoverTypes(); -UI_BASE_EXPORT void SetAvailablePointerAndHoverTypesForTesting( - int available_pointer_types, - int available_hover_types); -UI_BASE_EXPORT PointerType GetPrimaryPointerType(int available_pointer_types); -UI_BASE_EXPORT HoverType GetPrimaryHoverType(int available_hover_types); +COMPONENT_EXPORT(UI_BASE) +std::pair GetAvailablePointerAndHoverTypes(); +COMPONENT_EXPORT(UI_BASE) +void SetAvailablePointerAndHoverTypesForTesting(int available_pointer_types, + int available_hover_types); +COMPONENT_EXPORT(UI_BASE) +PointerType GetPrimaryPointerType(int available_pointer_types); +COMPONENT_EXPORT(UI_BASE) +HoverType GetPrimaryHoverType(int available_hover_types); } // namespace ui diff --git a/chromium/ui/base/pointer/touch_editing_controller.h b/chromium/ui/base/pointer/touch_editing_controller.h index e55fb3c9be1..0797a4017af 100644 --- a/chromium/ui/base/pointer/touch_editing_controller.h +++ b/chromium/ui/base/pointer/touch_editing_controller.h @@ -5,6 +5,7 @@ #ifndef UI_BASE_POINTER_TOUCH_EDITING_CONTROLLER_H_ #define UI_BASE_POINTER_TOUCH_EDITING_CONTROLLER_H_ +#include "base/component_export.h" #include "ui/base/models/simple_menu_model.h" namespace gfx { @@ -17,7 +18,8 @@ namespace ui { // An interface implemented by widget that has text that can be selected/edited // using touch. -class UI_BASE_EXPORT TouchEditable : public ui::SimpleMenuModel::Delegate { +class COMPONENT_EXPORT(UI_BASE) TouchEditable + : public ui::SimpleMenuModel::Delegate { public: // Commands that all TouchEditables support: enum MenuCommands { @@ -79,7 +81,7 @@ class UI_BASE_EXPORT TouchEditable : public ui::SimpleMenuModel::Delegate { // This defines the callback interface for other code to be notified of changes // in the state of a TouchEditable. -class UI_BASE_EXPORT TouchEditingControllerDeprecated { +class COMPONENT_EXPORT(UI_BASE) TouchEditingControllerDeprecated { public: virtual ~TouchEditingControllerDeprecated() {} @@ -89,16 +91,9 @@ class UI_BASE_EXPORT TouchEditingControllerDeprecated { // Notifies the controller that the selection has changed. virtual void SelectionChanged() = 0; - - // Returns true if the user is currently dragging one of the handles. - virtual bool IsHandleDragInProgress() = 0; - - // Hides visible handles. According to the value of |quick|, handles might - // fade out quickly or slowly. - virtual void HideHandles(bool quick) = 0; }; -class UI_BASE_EXPORT TouchEditingControllerFactory { +class COMPONENT_EXPORT(UI_BASE) TouchEditingControllerFactory { public: virtual ~TouchEditingControllerFactory() {} diff --git a/chromium/ui/base/pointer/touch_ui_controller.cc b/chromium/ui/base/pointer/touch_ui_controller.cc index f594a6db23c..326da1df5d9 100644 --- a/chromium/ui/base/pointer/touch_ui_controller.cc +++ b/chromium/ui/base/pointer/touch_ui_controller.cc @@ -4,11 +4,13 @@ #include "ui/base/pointer/touch_ui_controller.h" +#include #include #include "base/bind.h" #include "base/command_line.h" #include "base/message_loop/message_loop_current.h" +#include "base/metrics/user_metrics.h" #include "base/no_destructor.h" #include "base/trace_event/trace_event.h" #include "ui/base/ui_base_switches.h" @@ -22,17 +24,27 @@ namespace ui { -#if defined(OS_WIN) namespace { +#if defined(OS_WIN) + bool IsTabletMode() { return base::win::IsWindows10TabletMode( gfx::SingletonHwnd::GetInstance()->hwnd()); } -} // namespace #endif // defined(OS_WIN) +void RecordEnteredTouchMode() { + base::RecordAction(base::UserMetricsAction("TouchMode.EnteredTouchMode")); +} + +void RecordEnteredNonTouchMode() { + base::RecordAction(base::UserMetricsAction("TouchMode.EnteredNonTouchMode")); +} + +} // namespace + TouchUiController::TouchUiScoperForTesting::TouchUiScoperForTesting( bool enabled, TouchUiController* controller) @@ -44,6 +56,11 @@ TouchUiController::TouchUiScoperForTesting::~TouchUiScoperForTesting() { controller_->SetTouchUiState(old_state_); } +void TouchUiController::TouchUiScoperForTesting::UpdateState(bool enabled) { + controller_->SetTouchUiState(enabled ? TouchUiState::kEnabled + : TouchUiState::kDisabled); +} + // static TouchUiController* TouchUiController::Get() { static base::NoDestructor instance([] { @@ -72,6 +89,11 @@ TouchUiController::TouchUiController(TouchUiState touch_ui_state) tablet_mode_ = IsTabletMode(); } #endif + + if (touch_ui()) + RecordEnteredTouchMode(); + else + RecordEnteredNonTouchMode(); } TouchUiController::~TouchUiController() = default; @@ -79,10 +101,8 @@ TouchUiController::~TouchUiController() = default; void TouchUiController::OnTabletModeToggled(bool enabled) { const bool was_touch_ui = touch_ui(); tablet_mode_ = enabled; - if (touch_ui() != was_touch_ui) { - TRACE_EVENT0("ui", "TouchUiController.NotifyListeners"); - callback_list_.Notify(); - } + if (touch_ui() != was_touch_ui) + TouchUiChanged(); } std::unique_ptr @@ -94,11 +114,19 @@ TouchUiController::TouchUiState TouchUiController::SetTouchUiState( TouchUiState touch_ui_state) { const bool was_touch_ui = touch_ui(); const TouchUiState old_state = std::exchange(touch_ui_state_, touch_ui_state); - if (touch_ui() != was_touch_ui) { - TRACE_EVENT0("ui", "TouchUiController.NotifyListeners"); - callback_list_.Notify(); - } + if (touch_ui() != was_touch_ui) + TouchUiChanged(); return old_state; } +void TouchUiController::TouchUiChanged() { + if (touch_ui()) + RecordEnteredTouchMode(); + else + RecordEnteredNonTouchMode(); + + TRACE_EVENT0("ui", "TouchUiController.NotifyListeners"); + callback_list_.Notify(); +} + } // namespace ui diff --git a/chromium/ui/base/pointer/touch_ui_controller.h b/chromium/ui/base/pointer/touch_ui_controller.h index cecd4ddcc69..0240f4eaef3 100644 --- a/chromium/ui/base/pointer/touch_ui_controller.h +++ b/chromium/ui/base/pointer/touch_ui_controller.h @@ -5,11 +5,12 @@ #ifndef UI_BASE_POINTER_TOUCH_UI_CONTROLLER_H_ #define UI_BASE_POINTER_TOUCH_UI_CONTROLLER_H_ +#include #include #include "base/callback_list.h" +#include "base/component_export.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" #if defined(OS_WIN) namespace gfx { @@ -20,7 +21,7 @@ class SingletonHwndObserver; namespace ui { // Central controller to handle touch UI modes. -class UI_BASE_EXPORT TouchUiController { +class COMPONENT_EXPORT(UI_BASE) TouchUiController { public: using CallbackList = base::CallbackList; using Subscription = CallbackList::Subscription; @@ -31,7 +32,7 @@ class UI_BASE_EXPORT TouchUiController { kEnabled, }; - class UI_BASE_EXPORT TouchUiScoperForTesting { + class COMPONENT_EXPORT(UI_BASE) TouchUiScoperForTesting { public: explicit TouchUiScoperForTesting(bool enabled, TouchUiController* controller = Get()); @@ -39,6 +40,11 @@ class UI_BASE_EXPORT TouchUiController { TouchUiScoperForTesting& operator=(const TouchUiScoperForTesting&) = delete; ~TouchUiScoperForTesting(); + // Update the current touch mode state but still roll back to the + // original state at destruction. Allows a test to change the mode + // multiple times without creating multiple instances. + void UpdateState(bool enabled); + private: TouchUiController* const controller_; const TouchUiState old_state_; @@ -64,6 +70,8 @@ class UI_BASE_EXPORT TouchUiController { private: TouchUiState SetTouchUiState(TouchUiState touch_ui_state); + void TouchUiChanged(); + bool tablet_mode_ = false; TouchUiState touch_ui_state_; diff --git a/chromium/ui/base/resource/data_pack.cc b/chromium/ui/base/resource/data_pack.cc index 618204dfcda..09513e6aed2 100644 --- a/chromium/ui/base/resource/data_pack.cc +++ b/chromium/ui/base/resource/data_pack.cc @@ -10,6 +10,7 @@ #include #include "base/command_line.h" +#include "base/files/file.h" #include "base/files/file_util.h" #include "base/files/memory_mapped_file.h" #include "base/logging.h" @@ -41,8 +42,11 @@ static const size_t kHeaderLengthV5 = // We're crashing when trying to load a pak file on Windows. Add some error // codes for logging. // http://crbug.com/58056 +// These values are logged to UMA. Entries should not be renumbered and +// numeric values should never be reused. Keep in sync with "DataPackLoadErrors" +// in src/tools/metrics/histograms/enums.xml. enum LoadErrors { - INIT_FAILED = 1, + INIT_FAILED_OBSOLETE = 1, BAD_VERSION, INDEX_TRUNCATED, ENTRY_NOT_FOUND, @@ -50,6 +54,8 @@ enum LoadErrors { WRONG_ENCODING, INIT_FAILED_FROM_FILE, UNZIP_FAILED, + OPEN_FAILED, + MAP_FAILED, LOAD_ERRORS_COUNT, }; @@ -274,9 +280,20 @@ DataPack::~DataPack() { bool DataPack::LoadFromPath(const base::FilePath& path) { std::unique_ptr mmap = std::make_unique(); - if (!mmap->Initialize(path)) { + // Open the file for reading; allowing other consumers to also open it for + // reading and deleting. Do not allow others to write to it. + base::File data_file(path, base::File::FLAG_OPEN | base::File::FLAG_READ | + base::File::FLAG_EXCLUSIVE_WRITE | + base::File::FLAG_SHARE_DELETE); + if (!data_file.IsValid()) { + DLOG(ERROR) << "Failed to open datapack with base::File::Error " + << data_file.error_details(); + LogDataPackError(OPEN_FAILED); + return false; + } + if (!mmap->Initialize(std::move(data_file))) { DLOG(ERROR) << "Failed to mmap datapack"; - LogDataPackError(INIT_FAILED); + LogDataPackError(MAP_FAILED); return false; } if (MmapHasGzipHeader(mmap.get())) { diff --git a/chromium/ui/base/resource/resource_bundle.cc b/chromium/ui/base/resource/resource_bundle.cc index 133540ca848..eeb09546b45 100644 --- a/chromium/ui/base/resource/resource_bundle.cc +++ b/chromium/ui/base/resource/resource_bundle.cc @@ -12,10 +12,12 @@ #include "base/big_endian.h" #include "base/command_line.h" +#include "base/debug/alias.h" #include "base/files/file.h" #include "base/files/file_util.h" #include "base/logging.h" #include "base/memory/ref_counted_memory.h" +#include "base/notreached.h" #include "base/path_service.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" @@ -45,6 +47,7 @@ #include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia_source.h" #include "ui/strings/grit/app_locale_settings.h" +#include "url/gurl.h" #if defined(OS_ANDROID) #include "base/android/build_info.h" @@ -257,7 +260,9 @@ std::string ResourceBundle::InitSharedInstanceWithLocale( InitSharedInstance(delegate); if (load_resources == LOAD_COMMON_RESOURCES) g_shared_instance_->LoadCommonResources(); - std::string result = g_shared_instance_->LoadLocaleResources(pref_locale); + std::string result = + g_shared_instance_->LoadLocaleResources(pref_locale, + /*crash_on_failure=*/true); g_shared_instance_->InitDefaultFontList(); return result; } @@ -326,7 +331,8 @@ void ResourceBundle::LoadSecondaryLocaleDataWithPakFileRegion( #if !defined(OS_ANDROID) // static bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { - return !GetLocaleFilePath(locale).empty(); + const auto path = GetLocaleFilePath(locale); + return !path.empty() && base::PathExists(path); } #endif // !defined(OS_ANDROID) @@ -378,10 +384,7 @@ base::FilePath ResourceBundle::GetLocaleFilePath( return base::FilePath(); base::FilePath locale_file_path; - - base::PathService::Get(ui::DIR_LOCALES, &locale_file_path); - - if (!locale_file_path.empty()) { + if (base::PathService::Get(ui::DIR_LOCALES, &locale_file_path)) { #if defined(OS_ANDROID) if (locale_file_path.value().find("chromium_tests") == std::string::npos) { std::string extracted_file_suffix = @@ -410,20 +413,14 @@ base::FilePath ResourceBundle::GetLocaleFilePath( locale_file_path, app_locale); } - // Don't try to load empty values or values that are not absolute paths. - if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) - return base::FilePath(); - - if (base::PathExists(locale_file_path)) - return locale_file_path; - - return base::FilePath(); + // Don't try to load from paths that are not absolute. + return locale_file_path.IsAbsolute() ? locale_file_path : base::FilePath(); } #endif #if !defined(OS_ANDROID) -std::string ResourceBundle::LoadLocaleResources( - const std::string& pref_locale) { +std::string ResourceBundle::LoadLocaleResources(const std::string& pref_locale, + bool crash_on_failure) { DCHECK(!locale_resources_data_.get()) << "locale.pak already loaded"; std::string app_locale = l10n_util::GetApplicationLocale(pref_locale); base::FilePath locale_file_path = GetOverriddenPakPath(); @@ -437,10 +434,18 @@ std::string ResourceBundle::LoadLocaleResources( } std::unique_ptr data_pack(new DataPack(SCALE_FACTOR_100P)); - if (!data_pack->LoadFromPath(locale_file_path)) { - LOG(ERROR) << "failed to load locale file: " << locale_file_path; - NOTREACHED(); - return std::string(); + if (!data_pack->LoadFromPath(locale_file_path) && crash_on_failure) { + // https://crbug.com/1076423: Chrome can't start when the locale file cannot + // be loaded. Crash early and gather some data. +#if defined(OS_WIN) + const auto last_error = ::GetLastError(); + base::debug::Alias(&last_error); + wchar_t path_copy[MAX_PATH]; + base::wcslcpy(path_copy, locale_file_path.value().c_str(), + base::size(path_copy)); + base::debug::Alias(path_copy); +#endif // defined(OS_WIN) + CHECK(false); } locale_resources_data_ = std::move(data_pack); @@ -500,6 +505,12 @@ base::string16 ResourceBundle::MaybeMangleLocalizedString( if (base::StringToInt(str, &ignored)) return str; + // IDS_WEBSTORE_URL and some other resources are localization "strings" that + // are actually URLs, where the "localized" part is actually just the language + // code embedded in the URL. Don't mangle any URL. + if (GURL(str).is_valid()) + return str; + // For a string S, produce [[ --- S --- ]], where the number of dashes is 1/4 // of the number of characters in S. This makes S something around 50-75% // longer, except for extremely short strings, which get > 100% longer. @@ -518,7 +529,7 @@ std::string ResourceBundle::ReloadLocaleResources( overridden_locale_strings_.clear(); UnloadLocaleResources(); - return LoadLocaleResources(pref_locale); + return LoadLocaleResources(pref_locale, /*crash_on_failure=*/false); } gfx::ImageSkia* ResourceBundle::GetImageSkiaNamed(int resource_id) { diff --git a/chromium/ui/base/resource/resource_bundle.h b/chromium/ui/base/resource/resource_bundle.h index 0b62c5dba94..9cbc1d512ac 100644 --- a/chromium/ui/base/resource/resource_bundle.h +++ b/chromium/ui/base/resource/resource_bundle.h @@ -13,6 +13,7 @@ #include #include +#include "base/component_export.h" #include "base/files/file_path.h" #include "base/files/memory_mapped_file.h" #include "base/gtest_prod_util.h" @@ -21,7 +22,6 @@ #include "base/strings/string16.h" #include "base/strings/string_piece.h" #include "ui/base/layout.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/font_list.h" #include "ui/gfx/image/image.h" #include "ui/gfx/native_widget_types.h" @@ -41,7 +41,7 @@ class ResourceHandle; // ResourceBundle is a central facility to load images and other resources, // such as theme graphics. Every resource is loaded only once. -class UI_BASE_EXPORT ResourceBundle { +class COMPONENT_EXPORT(UI_BASE) ResourceBundle { public: // Legacy font size deltas. Consider these to be magic numbers. New code // should declare their own size delta constant using an identifier that @@ -121,9 +121,10 @@ class UI_BASE_EXPORT ResourceBundle { // Initialize the ResourceBundle for this process. Does not take ownership of // the |delegate| value. Returns the language selected or an empty string if - // initialization failed (e.g. resource bundle not found or corrupted). - // NOTE: Mac ignores this and always loads up resources for the language - // defined by the Cocoa UI (i.e., NSBundle does the language work). + // no candidate bundle file could be determined, or crashes the process if a + // candidate could not be loaded (e.g., file not found or corrupted). NOTE: + // Mac ignores this and always loads up resources for the language defined by + // the Cocoa UI (i.e., NSBundle does the language work). // // TODO(sergeyu): This method also loads common resources (i.e. chrome.pak). // There is no way to specify which resource files are loaded, i.e. names of @@ -323,8 +324,10 @@ class UI_BASE_EXPORT ResourceBundle { const base::string16& string); // Returns the full pathname of the locale file to load, which may be a - // compressed locale file ending in .gz. Returns an empty string if no locale - // data files are found. + // compressed locale file ending in .gz. Returns an empty path if |app_locale| + // is empty, the directory of locale files cannot be determined, or if the + // path to the directory of locale files is relative. If not empty, the + // returned path is not guaranteed to reference an existing file. // Used on Android to load the local file in the browser process and pass it // to the sandboxed renderer process. static base::FilePath GetLocaleFilePath(const std::string& app_locale); @@ -396,8 +399,11 @@ class UI_BASE_EXPORT ResourceBundle { void AddDataPack(std::unique_ptr data_pack); // Try to load the locale specific strings from an external data module. - // Returns the locale that is loaded. - std::string LoadLocaleResources(const std::string& pref_locale); + // Returns the locale that is loaded or an empty string if no resources were + // loaded. If |crash_on_failure| is true on non-Android platforms, the process + // is terminated if a candidate locale file could not be loaded. + std::string LoadLocaleResources(const std::string& pref_locale, + bool crash_on_failure); // Load test resources in given paths. If either path is empty an empty // resource pack is loaded. diff --git a/chromium/ui/base/resource/resource_bundle_android.cc b/chromium/ui/base/resource/resource_bundle_android.cc index c86a3bfa2bd..e8cf7b78c66 100644 --- a/chromium/ui/base/resource/resource_bundle_android.cc +++ b/chromium/ui/base/resource/resource_bundle_android.cc @@ -4,10 +4,14 @@ #include "ui/base/resource/resource_bundle_android.h" +#include + #include "base/android/apk_assets.h" #include "base/android/jni_android.h" #include "base/android/jni_string.h" +#include "base/files/file_util.h" #include "base/logging.h" +#include "base/notreached.h" #include "base/path_service.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/data_pack.h" @@ -56,11 +60,10 @@ bool LoadFromApkOrFile(const char* apk_path, int LoadLocalePakFromApk(const std::string& app_locale, bool in_split, base::MemoryMappedFile::Region* out_region) { + bool log_error = true; std::string locale_path_within_apk = - GetPathForAndroidLocalePakWithinApk(app_locale, in_split); + GetPathForAndroidLocalePakWithinApk(app_locale, in_split, log_error); if (locale_path_within_apk.empty()) { - LOG(WARNING) << "locale_path_within_apk.empty() for locale " - << app_locale; return -1; } return base::android::OpenApkAsset(locale_path_within_apk, out_region); @@ -95,16 +98,20 @@ void ResourceBundle::LoadCommonResources() { // static bool ResourceBundle::LocaleDataPakExists(const std::string& locale) { - if (g_locale_paks_in_apk) { - return !GetPathForAndroidLocalePakWithinApk(locale, false).empty(); + bool log_error = false; + bool in_split = !g_locale_paks_in_apk; + if (!in_split) { + return !GetPathForAndroidLocalePakWithinApk(locale, in_split, log_error) + .empty(); } - if (!GetPathForAndroidLocalePakWithinApk(locale, true).empty()) + if (!GetPathForAndroidLocalePakWithinApk(locale, in_split, log_error).empty()) return true; - return !GetLocaleFilePath(locale).empty(); + const auto path = GetLocaleFilePath(locale); + return !path.empty() && base::PathExists(path); } -std::string ResourceBundle::LoadLocaleResources( - const std::string& pref_locale) { +std::string ResourceBundle::LoadLocaleResources(const std::string& pref_locale, + bool crash_on_failure) { DCHECK(!locale_resources_data_.get() && !secondary_locale_resources_data_.get()) << "locale.pak already loaded"; @@ -166,8 +173,11 @@ std::string ResourceBundle::LoadLocaleResources( } if (g_locale_pack_fd < 0) { // Otherwise, try to locate the extracted locale .pak file. - if (locale_file_path.empty()) - locale_file_path = GetLocaleFilePath(app_locale); + if (locale_file_path.empty()) { + auto path = GetLocaleFilePath(app_locale); + if (base::PathExists(path)) + locale_file_path = std::move(path); + } if (locale_file_path.empty()) { // It's possible that there is no locale.pak. @@ -260,11 +270,13 @@ int GetSecondaryLocalePackFd(base::MemoryMappedFile::Region* out_region) { } std::string GetPathForAndroidLocalePakWithinApk(const std::string& locale, - bool in_bundle) { + bool in_bundle, + bool log_error) { JNIEnv* env = base::android::AttachCurrentThread(); base::android::ScopedJavaLocalRef ret = Java_ResourceBundle_getLocalePakResourcePath( - env, base::android::ConvertUTF8ToJavaString(env, locale), in_bundle); + env, base::android::ConvertUTF8ToJavaString(env, locale), in_bundle, + log_error); if (ret.obj() == nullptr) { return std::string(); } diff --git a/chromium/ui/base/resource/resource_bundle_android.h b/chromium/ui/base/resource/resource_bundle_android.h index e02fc11568f..99096888fc9 100644 --- a/chromium/ui/base/resource/resource_bundle_android.h +++ b/chromium/ui/base/resource/resource_bundle_android.h @@ -8,55 +8,57 @@ #include #include +#include "base/component_export.h" #include "base/files/memory_mapped_file.h" -#include "ui/base/ui_base_export.h" namespace ui { // Loads "resources.apk" from the .apk. Falls back to loading from disk, which // is necessary for tests. -UI_BASE_EXPORT void LoadMainAndroidPackFile( - const char* path_within_apk, - const base::FilePath& disk_file_path); +COMPONENT_EXPORT(UI_BASE) +void LoadMainAndroidPackFile(const char* path_within_apk, + const base::FilePath& disk_file_path); // Loads a PAK file from the APK and makes the contained resources accessible. -UI_BASE_EXPORT void LoadPackFileFromApk(const std::string& path); +COMPONENT_EXPORT(UI_BASE) void LoadPackFileFromApk(const std::string& path); // Returns the file descriptor and region for resources.pak. -UI_BASE_EXPORT int GetMainAndroidPackFd( - base::MemoryMappedFile::Region* out_region); +COMPONENT_EXPORT(UI_BASE) +int GetMainAndroidPackFd(base::MemoryMappedFile::Region* out_region); // Returns the file descriptor and region for chrome_100_percent.pak. -UI_BASE_EXPORT int GetCommonResourcesPackFd( - base::MemoryMappedFile::Region* out_region); +COMPONENT_EXPORT(UI_BASE) +int GetCommonResourcesPackFd(base::MemoryMappedFile::Region* out_region); // Returns the file descriptor and region for the locale .pak file. -UI_BASE_EXPORT int GetLocalePackFd( - base::MemoryMappedFile::Region* out_region); +COMPONENT_EXPORT(UI_BASE) +int GetLocalePackFd(base::MemoryMappedFile::Region* out_region); // Returns the file descriptor and region for the secondary locale .pak file. -UI_BASE_EXPORT int GetSecondaryLocalePackFd( - base::MemoryMappedFile::Region* out_region); +COMPONENT_EXPORT(UI_BASE) +int GetSecondaryLocalePackFd(base::MemoryMappedFile::Region* out_region); // Tell ResourceBundle to locate locale pak files via // GetPathForAndroidLocalePakWithinApk rather than looking for them on disk. -UI_BASE_EXPORT void SetLocalePaksStoredInApk(bool value); +COMPONENT_EXPORT(UI_BASE) void SetLocalePaksStoredInApk(bool value); // Tell ResourceBundle to load secondary locale .pak files. -UI_BASE_EXPORT void SetLoadSecondaryLocalePaks(bool value); +COMPONENT_EXPORT(UI_BASE) void SetLoadSecondaryLocalePaks(bool value); // Returns the path within the apk for the given locale's .pak file, or an // empty string if it doesn't exist. // Only locale paks for the active Android language can be retrieved. -// If |inSplit| is true, look into bundle split-specific location (e.g. +// If |in_split| is true, look into bundle split-specific location (e.g. // 'assets/locales#lang_/.pak', otherwise use the default // WebView-related location, i.e. 'assets/stored-locales/.pak'. -UI_BASE_EXPORT std::string GetPathForAndroidLocalePakWithinApk( - const std::string& locale, - bool in_split = false); +// If |log_error|, logs the path to logcat, but does not abort. +COMPONENT_EXPORT(UI_BASE) +std::string GetPathForAndroidLocalePakWithinApk(const std::string& locale, + bool in_split, + bool log_error); // Called in test when there are no locale pak files available. -UI_BASE_EXPORT void SetNoAvailableLocalePaksForTest(); +COMPONENT_EXPORT(UI_BASE) void SetNoAvailableLocalePaksForTest(); // Get the density of the primary display. Use this instead of using Display // to avoid initializing Display in child processes. diff --git a/chromium/ui/base/resource/resource_bundle_ios.mm b/chromium/ui/base/resource/resource_bundle_ios.mm index 111786882c6..f623bdf562d 100644 --- a/chromium/ui/base/resource/resource_bundle_ios.mm +++ b/chromium/ui/base/resource/resource_bundle_ios.mm @@ -13,6 +13,7 @@ #include "base/mac/foundation_util.h" #include "base/mac/scoped_nsobject.h" #include "base/memory/ref_counted_memory.h" +#include "base/notreached.h" #include "base/strings/sys_string_conversions.h" #include "base/synchronization/lock.h" #include "ui/base/resource/resource_handle.h" @@ -80,14 +81,8 @@ base::FilePath ResourceBundle::GetLocaleFilePath( locale_file_path, app_locale); } - // Don't try to load empty values or values that are not absolute paths. - if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) - return base::FilePath(); - - if (!base::PathExists(locale_file_path)) - return base::FilePath(); - - return locale_file_path; + // Don't try to load from paths that are not absolute. + return locale_file_path.IsAbsolute() ? locale_file_path : base::FilePath(); } gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { diff --git a/chromium/ui/base/resource/resource_bundle_mac.mm b/chromium/ui/base/resource/resource_bundle_mac.mm index 6bd9d7aff19..87921ce6c6b 100644 --- a/chromium/ui/base/resource/resource_bundle_mac.mm +++ b/chromium/ui/base/resource/resource_bundle_mac.mm @@ -9,9 +9,11 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" +#include "base/logging.h" #include "base/mac/bundle_locations.h" #include "base/mac/scoped_nsobject.h" #include "base/memory/ref_counted_memory.h" +#include "base/notreached.h" #include "base/strings/sys_string_conversions.h" #include "base/synchronization/lock.h" #include "ui/base/resource/resource_handle.h" @@ -80,14 +82,8 @@ base::FilePath ResourceBundle::GetLocaleFilePath( locale_file_path, app_locale); } - // Don't try to load empty values or values that are not absolute paths. - if (locale_file_path.empty() || !locale_file_path.IsAbsolute()) - return base::FilePath(); - - if (!base::PathExists(locale_file_path)) - return base::FilePath(); - - return locale_file_path; + // Don't try to load from paths that are not absolute. + return locale_file_path.IsAbsolute() ? locale_file_path : base::FilePath(); } gfx::Image& ResourceBundle::GetNativeImageNamed(int resource_id) { diff --git a/chromium/ui/base/resource/resource_bundle_unittest.cc b/chromium/ui/base/resource/resource_bundle_unittest.cc index 904695c9291..bfa3dab5e80 100644 --- a/chromium/ui/base/resource/resource_bundle_unittest.cc +++ b/chromium/ui/base/resource/resource_bundle_unittest.cc @@ -163,16 +163,16 @@ TEST_F(ResourceBundleTest, DelegateGetPathForLocalePack) { .RetiresOnSaturation(); EXPECT_FALSE(ResourceBundle::LocaleDataPakExists(locale)); - EXPECT_EQ("", - ResourceBundle::GetSharedInstance().LoadLocaleResources(locale)); + EXPECT_EQ("", ResourceBundle::GetSharedInstance().LoadLocaleResources( + locale, /*crash_on_failure=*/false)); // Allow the load to proceed. EXPECT_CALL(delegate, GetPathForLocalePack(_, _)) .WillRepeatedly(ReturnArg<0>()); EXPECT_TRUE(ResourceBundle::LocaleDataPakExists(locale)); - EXPECT_EQ(locale, - ResourceBundle::GetSharedInstance().LoadLocaleResources(locale)); + EXPECT_EQ(locale, ResourceBundle::GetSharedInstance().LoadLocaleResources( + locale, /*crash_on_failure=*/false)); ResourceBundle::CleanupSharedInstance(); ResourceBundle::SwapSharedInstanceForTesting(orig_instance); diff --git a/chromium/ui/base/resource/resource_bundle_win.h b/chromium/ui/base/resource/resource_bundle_win.h index 92590eaff97..167f40c1ce3 100644 --- a/chromium/ui/base/resource/resource_bundle_win.h +++ b/chromium/ui/base/resource/resource_bundle_win.h @@ -9,16 +9,16 @@ #include -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { // NOTE: This needs to be called before initializing ResourceBundle if your // resources are not stored in the executable. -UI_BASE_EXPORT void SetResourcesDataDLL(HINSTANCE handle); +COMPONENT_EXPORT(UI_BASE) void SetResourcesDataDLL(HINSTANCE handle); // Loads and returns an icon from the app module. -UI_BASE_EXPORT HICON LoadThemeIconFromResourcesDataDLL(int icon_id); +COMPONENT_EXPORT(UI_BASE) HICON LoadThemeIconFromResourcesDataDLL(int icon_id); } // namespace ui diff --git a/chromium/ui/base/scoped_visibility_tracker.h b/chromium/ui/base/scoped_visibility_tracker.h index b351b57099e..2f53bc552b3 100644 --- a/chromium/ui/base/scoped_visibility_tracker.h +++ b/chromium/ui/base/scoped_visibility_tracker.h @@ -7,8 +7,8 @@ #include +#include "base/component_export.h" #include "base/time/time.h" -#include "ui/base/ui_base_export.h" namespace base { class TickClock; @@ -18,7 +18,7 @@ namespace ui { // This class tracks the total time it is visible, based on receiving // OnShown/OnHidden notifications, which are logically idempotent. -class UI_BASE_EXPORT ScopedVisibilityTracker { +class COMPONENT_EXPORT(UI_BASE) ScopedVisibilityTracker { public: // |tick_clock| must outlive this object. ScopedVisibilityTracker(const base::TickClock* tick_clock, bool is_shown); diff --git a/chromium/ui/base/template_expressions.cc b/chromium/ui/base/template_expressions.cc index 2d7af5e5bc4..2f6573447c6 100644 --- a/chromium/ui/base/template_expressions.cc +++ b/chromium/ui/base/template_expressions.cc @@ -6,6 +6,8 @@ #include +#include + #include "base/check_op.h" #include "base/optional.h" #include "base/stl_util.h" diff --git a/chromium/ui/base/template_expressions.h b/chromium/ui/base/template_expressions.h index a12f5b2fad8..470d54b3734 100644 --- a/chromium/ui/base/template_expressions.h +++ b/chromium/ui/base/template_expressions.h @@ -11,8 +11,8 @@ #include #include +#include "base/component_export.h" #include "base/strings/string_piece.h" -#include "ui/base/ui_base_export.h" namespace base { class DictionaryValue; @@ -26,14 +26,16 @@ typedef std::map TemplateReplacements; // Convert a dictionary to a replacement map. This helper function is to assist // migration to using TemplateReplacements directly (which is preferred). // TODO(dschuyler): remove this function by using TemplateReplacements directly. -UI_BASE_EXPORT void TemplateReplacementsFromDictionaryValue( +COMPONENT_EXPORT(UI_BASE) +void TemplateReplacementsFromDictionaryValue( const base::DictionaryValue& dictionary, TemplateReplacements* replacements); // Replace $i18n*{foo} in the format string with the value for the foo key in // |replacements|. If the key is not found in the |replacements| that item will // be unaltered. -UI_BASE_EXPORT std::string ReplaceTemplateExpressions( +COMPONENT_EXPORT(UI_BASE) +std::string ReplaceTemplateExpressions( base::StringPiece source, const TemplateReplacements& replacements, bool skip_unexpected_placeholder_check = false); @@ -51,10 +53,10 @@ UI_BASE_EXPORT std::string ReplaceTemplateExpressions( // backticks or "${" within the HTML string). // Note: Currently, this only supports the legacy Polymer syntax, i.e.: // _template: html` ... `, -UI_BASE_EXPORT bool ReplaceTemplateExpressionsInJS( - base::StringPiece source, - const TemplateReplacements& replacements, - std::string* output); +COMPONENT_EXPORT(UI_BASE) +bool ReplaceTemplateExpressionsInJS(base::StringPiece source, + const TemplateReplacements& replacements, + std::string* output); } // namespace ui diff --git a/chromium/ui/base/text/bytes_formatting.h b/chromium/ui/base/text/bytes_formatting.h index 7cb6e45ce62..424d5297435 100644 --- a/chromium/ui/base/text/bytes_formatting.h +++ b/chromium/ui/base/text/bytes_formatting.h @@ -7,8 +7,8 @@ #include +#include "base/component_export.h" #include "base/strings/string16.h" -#include "ui/base/ui_base_export.h" namespace ui { @@ -17,12 +17,12 @@ namespace ui { // Simple call to return a byte quantity as a string in human-readable format. // Ex: FormatBytes(512) => "512 B" // Ex: FormatBytes(101479) => "99.1 kB" -UI_BASE_EXPORT base::string16 FormatBytes(int64_t bytes); +COMPONENT_EXPORT(UI_BASE) base::string16 FormatBytes(int64_t bytes); // Simple call to return a speed as a string in human-readable format. // Ex: FormatSpeed(512) => "512 B/s" // Ex: FormatSpeed(101479) => "99.1 kB/s" -UI_BASE_EXPORT base::string16 FormatSpeed(int64_t bytes); +COMPONENT_EXPORT(UI_BASE) base::string16 FormatSpeed(int64_t bytes); // Less-Simple API ------------------------------------------------------------- @@ -38,15 +38,16 @@ enum DataUnits { // Return the unit type that is appropriate for displaying the amount of bytes // passed in. Most of the time, an explicit call to this isn't necessary; just // use FormatBytes()/FormatSpeed() above. -UI_BASE_EXPORT DataUnits GetByteDisplayUnits(int64_t bytes); +COMPONENT_EXPORT(UI_BASE) DataUnits GetByteDisplayUnits(int64_t bytes); // Return a byte quantity as a string in human-readable format with an optional // unit suffix. Specify in the |units| argument the units to be used. // Ex: FormatBytes(512, DATA_UNITS_KIBIBYTE, true) => "0.5 kB" // Ex: FormatBytes(10*1024, DATA_UNITS_MEBIBYTE, false) => "0.1" -UI_BASE_EXPORT base::string16 FormatBytesWithUnits(int64_t bytes, - DataUnits units, - bool show_units); +COMPONENT_EXPORT(UI_BASE) +base::string16 FormatBytesWithUnits(int64_t bytes, + DataUnits units, + bool show_units); // As above, but with "/s" units for speed values. // Ex: FormatSpeed(512, DATA_UNITS_KIBIBYTE, true) => "0.5 kB/s" diff --git a/chromium/ui/base/theme_provider.h b/chromium/ui/base/theme_provider.h index 514a9ae4545..f47a724d56d 100644 --- a/chromium/ui/base/theme_provider.h +++ b/chromium/ui/base/theme_provider.h @@ -5,9 +5,9 @@ #ifndef UI_BASE_THEME_PROVIDER_H_ #define UI_BASE_THEME_PROVIDER_H_ +#include "base/component_export.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/base/layout.h" -#include "ui/base/ui_base_export.h" namespace base { class RefCountedMemory; @@ -32,7 +32,7 @@ namespace ui { // //////////////////////////////////////////////////////////////////////////////// -class UI_BASE_EXPORT ThemeProvider { +class COMPONENT_EXPORT(UI_BASE) ThemeProvider { public: virtual ~ThemeProvider(); diff --git a/chromium/ui/base/ui_base_export.h b/chromium/ui/base/ui_base_export.h deleted file mode 100644 index dba9b898029..00000000000 --- a/chromium/ui/base/ui_base_export.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_BASE_UI_BASE_EXPORT_H_ -#define UI_BASE_UI_BASE_EXPORT_H_ - -// Defines UI_BASE_EXPORT so that functionality implemented by the UI module -// can be exported to consumers. - -#if defined(COMPONENT_BUILD) - -#if defined(WIN32) - -#if defined(UI_BASE_IMPLEMENTATION) -#define UI_BASE_EXPORT __declspec(dllexport) -#else -#define UI_BASE_EXPORT __declspec(dllimport) -#endif - -#else // !defined(WIN32) - -#if defined(UI_BASE_IMPLEMENTATION) -#define UI_BASE_EXPORT __attribute__((visibility("default"))) -#else -#define UI_BASE_EXPORT -#endif - -#endif - -#else // !defined(COMPONENT_BUILD) - -#define UI_BASE_EXPORT - -#endif - -#endif // UI_BASE_UI_BASE_EXPORT_H_ diff --git a/chromium/ui/base/ui_base_features.cc b/chromium/ui/base/ui_base_features.cc index 7050729f302..3a6ee833e13 100644 --- a/chromium/ui/base/ui_base_features.cc +++ b/chromium/ui/base/ui_base_features.cc @@ -161,6 +161,18 @@ bool IsEyeDropperEnabled() { base::FeatureList::IsEnabled(features::kEyeDropper); } +// Enable the CSSColorSchemeUARendering feature for Windows, ChromeOS, Linux, +// and Mac. This feature will be released for Android in later milestones. See +// crbug.com/1086530 for the Desktop launch bug. +const base::Feature kCSSColorSchemeUARendering = { + "CSSColorSchemeUARendering", base::FEATURE_DISABLED_BY_DEFAULT}; + +bool IsCSSColorSchemeUARenderingEnabled() { + static const bool css_color_scheme_ua_rendering_enabled = + base::FeatureList::IsEnabled(features::kCSSColorSchemeUARendering); + return css_color_scheme_ua_rendering_enabled; +} + // Enable the FormControlsRefresh feature for Windows, ChromeOS, Linux, and Mac. // This feature will be released for Android in later milestones. See // crbug.com/1012106 for the Windows launch bug, and crbug.com/1012108 for the @@ -188,13 +200,9 @@ bool IsUseCommonSelectPopupEnabled() { return base::FeatureList::IsEnabled(features::kUseCommonSelectPopup); } -// Enable WebUI accessibility enhancements for review and testing. -const base::Feature kWebUIA11yEnhancements{"WebUIA11yEnhancements", - base::FEATURE_DISABLED_BY_DEFAULT}; - #if defined(OS_CHROMEOS) const base::Feature kHandwritingGesture = {"HandwritingGesture", - base::FEATURE_DISABLED_BY_DEFAULT}; + base::FEATURE_ENABLED_BY_DEFAULT}; #endif const base::Feature kSynchronousPageFlipTesting{ @@ -204,4 +212,30 @@ bool IsSynchronousPageFlipTestingEnabled() { return base::FeatureList::IsEnabled(kSynchronousPageFlipTesting); } +#if defined(USE_X11) || defined(USE_OZONE) +const base::Feature kUseOzonePlatform { + "UseOzonePlatform", +#if defined(USE_X11) + base::FEATURE_DISABLED_BY_DEFAULT +}; +#else + base::FEATURE_ENABLED_BY_DEFAULT +}; +#endif + +bool IsUsingOzonePlatform() { + // Only allow enabling and disabling the OzonePlatform on USE_X11 && USE_OZONE + // builds. +#if defined(USE_X11) && defined(USE_OZONE) + return base::FeatureList::IsEnabled(kUseOzonePlatform); +#elif defined(USE_X11) && !defined(USE_OZONE) + // This shouldn't be switchable for pure X11 builds. + return false; +#else + // All the other platforms must use Ozone by default and can't disable that. + return true; +#endif +} +#endif // defined(USE_X11) || defined(USE_OZONE) + } // namespace features diff --git a/chromium/ui/base/ui_base_features.h b/chromium/ui/base/ui_base_features.h index 83d7157f8d0..61f75131c9f 100644 --- a/chromium/ui/base/ui_base_features.h +++ b/chromium/ui/base/ui_base_features.h @@ -73,6 +73,11 @@ COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsForcedColorsEnabled(); COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kEyeDropper; COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsEyeDropperEnabled(); +// Used to enable form controls and scrollbar dark mode rendering. +COMPONENT_EXPORT(UI_BASE_FEATURES) +extern const base::Feature kCSSColorSchemeUARendering; +COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsCSSColorSchemeUARenderingEnabled(); + // Used to enable the new controls UI. COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kFormControlsRefresh; @@ -94,9 +99,6 @@ COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsNewShortcutMappingEnabled(); #endif -COMPONENT_EXPORT(UI_BASE_FEATURES) -extern const base::Feature kWebUIA11yEnhancements; - // Indicates whether DrmOverlayManager should used the synchronous API to // perform pageflip tests. COMPONENT_EXPORT(UI_BASE_FEATURES) @@ -105,6 +107,21 @@ extern const base::Feature kSynchronousPageFlipTesting; COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsSynchronousPageFlipTestingEnabled(); +#if defined(USE_X11) || defined(USE_OZONE) +// Indicates whether the OzonePlatform feature is used on Linux. Although, it is +// available for all Ozone platforms, this always resolves to true for +// non-desktop Linux builds. The reason why it is needed for all Ozone builds is +// that we have many places in the code that Ozone takes independently of the +// platform, and it's highly important that when USE_X11 && USE_OZONE are true +// and the OzonePlatform feature is not enabled, the Ozone path is never taken. +// This will be removed as soon as Ozone/Linux is default and USE_X11 is +// removed. More info at +// https://docs.google.com/document/d/1PvKquOHWySbvbe4bgduAcpW0Pda4BBhXI7xphtyDtPQ +COMPONENT_EXPORT(UI_BASE_FEATURES) extern const base::Feature kUseOzonePlatform; + +COMPONENT_EXPORT(UI_BASE_FEATURES) bool IsUsingOzonePlatform(); +#endif + } // namespace features #endif // UI_BASE_UI_BASE_FEATURES_H_ diff --git a/chromium/ui/base/ui_base_paths.h b/chromium/ui/base/ui_base_paths.h index cf5e0041e6f..fa61416237d 100644 --- a/chromium/ui/base/ui_base_paths.h +++ b/chromium/ui/base/ui_base_paths.h @@ -5,8 +5,8 @@ #ifndef UI_BASE_UI_BASE_PATHS_H_ #define UI_BASE_UI_BASE_PATHS_H_ +#include "base/component_export.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" // This file declares path keys for various special directories. These can be // used with the PathService to access these directories and files. @@ -31,7 +31,7 @@ enum { }; // Call once to register the provider for the path keys defined above. -UI_BASE_EXPORT void RegisterPathProvider(); +COMPONENT_EXPORT(UI_BASE) void RegisterPathProvider(); } // namespace ui diff --git a/chromium/ui/base/ui_base_switches.h b/chromium/ui/base/ui_base_switches.h index 26b8dbf13a1..8e7fb9e0c93 100644 --- a/chromium/ui/base/ui_base_switches.h +++ b/chromium/ui/base/ui_base_switches.h @@ -7,41 +7,41 @@ #ifndef UI_BASE_UI_BASE_SWITCHES_H_ #define UI_BASE_UI_BASE_SWITCHES_H_ +#include "base/component_export.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" namespace switches { #if defined(OS_MACOSX) && !defined(OS_IOS) -UI_BASE_EXPORT extern const char kDisableAVFoundationOverlays[]; -UI_BASE_EXPORT extern const char kDisableMacOverlays[]; -UI_BASE_EXPORT extern const char kDisableModalAnimations[]; -UI_BASE_EXPORT extern const char kDisableRemoteCoreAnimation[]; -UI_BASE_EXPORT extern const char kShowMacOverlayBorders[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableAVFoundationOverlays[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableMacOverlays[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableModalAnimations[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableRemoteCoreAnimation[]; +COMPONENT_EXPORT(UI_BASE) extern const char kShowMacOverlayBorders[]; #endif -UI_BASE_EXPORT extern const char kDisableCompositedAntialiasing[]; -UI_BASE_EXPORT extern const char kDisableDwmComposition[]; -UI_BASE_EXPORT extern const char kDisableTouchAdjustment[]; -UI_BASE_EXPORT extern const char kDisableTouchDragDrop[]; -UI_BASE_EXPORT extern const char kEnableTouchDragDrop[]; -UI_BASE_EXPORT extern const char kForceCaptionStyle[]; -UI_BASE_EXPORT extern const char kForceDarkMode[]; -UI_BASE_EXPORT extern const char kForceHighContrast[]; -UI_BASE_EXPORT extern const char kLang[]; -UI_BASE_EXPORT extern const char kShowOverdrawFeedback[]; -UI_BASE_EXPORT extern const char kSlowDownCompositingScaleFactor[]; -UI_BASE_EXPORT extern const char kTintGlCompositedContent[]; -UI_BASE_EXPORT extern const char kTopChromeTouchUi[]; -UI_BASE_EXPORT extern const char kTopChromeTouchUiAuto[]; -UI_BASE_EXPORT extern const char kTopChromeTouchUiDisabled[]; -UI_BASE_EXPORT extern const char kTopChromeTouchUiEnabled[]; -UI_BASE_EXPORT extern const char kUIDisablePartialSwap[]; -UI_BASE_EXPORT extern const char kUseSystemClipboard[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableCompositedAntialiasing[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableDwmComposition[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableTouchAdjustment[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisableTouchDragDrop[]; +COMPONENT_EXPORT(UI_BASE) extern const char kEnableTouchDragDrop[]; +COMPONENT_EXPORT(UI_BASE) extern const char kForceCaptionStyle[]; +COMPONENT_EXPORT(UI_BASE) extern const char kForceDarkMode[]; +COMPONENT_EXPORT(UI_BASE) extern const char kForceHighContrast[]; +COMPONENT_EXPORT(UI_BASE) extern const char kLang[]; +COMPONENT_EXPORT(UI_BASE) extern const char kShowOverdrawFeedback[]; +COMPONENT_EXPORT(UI_BASE) extern const char kSlowDownCompositingScaleFactor[]; +COMPONENT_EXPORT(UI_BASE) extern const char kTintGlCompositedContent[]; +COMPONENT_EXPORT(UI_BASE) extern const char kTopChromeTouchUi[]; +COMPONENT_EXPORT(UI_BASE) extern const char kTopChromeTouchUiAuto[]; +COMPONENT_EXPORT(UI_BASE) extern const char kTopChromeTouchUiDisabled[]; +COMPONENT_EXPORT(UI_BASE) extern const char kTopChromeTouchUiEnabled[]; +COMPONENT_EXPORT(UI_BASE) extern const char kUIDisablePartialSwap[]; +COMPONENT_EXPORT(UI_BASE) extern const char kUseSystemClipboard[]; // Test related. -UI_BASE_EXPORT extern const char kDisallowNonExactResourceReuse[]; -UI_BASE_EXPORT extern const char kMangleLocalizedStrings[]; +COMPONENT_EXPORT(UI_BASE) extern const char kDisallowNonExactResourceReuse[]; +COMPONENT_EXPORT(UI_BASE) extern const char kMangleLocalizedStrings[]; } // namespace switches diff --git a/chromium/ui/base/ui_base_switches_util.h b/chromium/ui/base/ui_base_switches_util.h index 2b6af8c1088..9928e56708b 100644 --- a/chromium/ui/base/ui_base_switches_util.h +++ b/chromium/ui/base/ui_base_switches_util.h @@ -5,11 +5,11 @@ #ifndef UI_BASE_UI_BASE_SWITCHES_UTIL_H_ #define UI_BASE_UI_BASE_SWITCHES_UTIL_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace switches { -UI_BASE_EXPORT bool IsTouchDragDropEnabled(); +COMPONENT_EXPORT(UI_BASE) bool IsTouchDragDropEnabled(); } // namespace switches diff --git a/chromium/ui/base/ui_base_types.h b/chromium/ui/base/ui_base_types.h index f79b03aaeb2..f290701526d 100644 --- a/chromium/ui/base/ui_base_types.h +++ b/chromium/ui/base/ui_base_types.h @@ -5,7 +5,7 @@ #ifndef UI_BASE_UI_BASE_TYPES_H_ #define UI_BASE_UI_BASE_TYPES_H_ -#include "ui/base/ui_base_export.h" +#include "base/component_export.h" namespace ui { @@ -93,7 +93,8 @@ enum MenuSourceType { MENU_SOURCE_TYPE_LAST = MENU_SOURCE_ADJUST_SELECTION_RESET }; -UI_BASE_EXPORT MenuSourceType GetMenuSourceTypeForEvent(const ui::Event& event); +COMPONENT_EXPORT(UI_BASE) +MenuSourceType GetMenuSourceTypeForEvent(const ui::Event& event); } // namespace ui diff --git a/chromium/ui/base/user_activity/user_activity_detector.h b/chromium/ui/base/user_activity/user_activity_detector.h index 0f2a9a9ec4b..caffb50fdf8 100644 --- a/chromium/ui/base/user_activity/user_activity_detector.h +++ b/chromium/ui/base/user_activity/user_activity_detector.h @@ -6,10 +6,10 @@ #define UI_BASE_USER_ACTIVITY_USER_ACTIVITY_DETECTOR_H_ #include "base/compiler_specific.h" +#include "base/component_export.h" #include "base/macros.h" #include "base/observer_list.h" #include "base/time/time.h" -#include "ui/base/ui_base_export.h" #include "ui/events/event.h" #include "ui/events/platform/platform_event_observer.h" @@ -18,7 +18,8 @@ namespace ui { class UserActivityObserver; // Watches for input events and notifies observers that the user is active. -class UI_BASE_EXPORT UserActivityDetector : public PlatformEventObserver { +class COMPONENT_EXPORT(UI_BASE) UserActivityDetector + : public PlatformEventObserver { public: // Minimum amount of time between notifications to observers. static const int kNotifyIntervalMs; diff --git a/chromium/ui/base/user_activity/user_activity_observer.h b/chromium/ui/base/user_activity/user_activity_observer.h index f6b98d210af..a83c8affd8e 100644 --- a/chromium/ui/base/user_activity/user_activity_observer.h +++ b/chromium/ui/base/user_activity/user_activity_observer.h @@ -5,8 +5,8 @@ #ifndef UI_BASE_USER_ACTIVITY_USER_ACTIVITY_OBSERVER_H_ #define UI_BASE_USER_ACTIVITY_USER_ACTIVITY_OBSERVER_H_ +#include "base/component_export.h" #include "base/macros.h" -#include "ui/base/ui_base_export.h" namespace ui { class Event; @@ -16,7 +16,7 @@ namespace ui { // Interface for classes that want to be notified about user activity. // Implementations should register themselves with UserActivityDetector. -class UI_BASE_EXPORT UserActivityObserver { +class COMPONENT_EXPORT(UI_BASE) UserActivityObserver { public: // Invoked periodically while the user is active (i.e. generating input // events). |event| is the event that triggered the notification; it may diff --git a/chromium/ui/base/view_prop.cc b/chromium/ui/base/view_prop.cc index 45185f5ffbe..33b38a2ff04 100644 --- a/chromium/ui/base/view_prop.cc +++ b/chromium/ui/base/view_prop.cc @@ -53,9 +53,7 @@ class ViewProp::Data : public base::RefCounted { typedef std::set DataSet; Data(gfx::AcceleratedWidget view, const char* key) - : view_(view), - key_(key), - data_(NULL) {} + : view_(view), key_(key), data_(nullptr) {} ~Data() { auto i = data_set_->find(this); diff --git a/chromium/ui/base/view_prop.h b/chromium/ui/base/view_prop.h index c81e995b0ba..c15007ae06a 100644 --- a/chromium/ui/base/view_prop.h +++ b/chromium/ui/base/view_prop.h @@ -5,10 +5,10 @@ #ifndef UI_BASE_VIEW_PROP_H_ #define UI_BASE_VIEW_PROP_H_ +#include "base/component_export.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "build/build_config.h" -#include "ui/base/ui_base_export.h" #include "ui/gfx/native_widget_types.h" #if !defined(OS_WIN) && !defined(USE_AURA) @@ -21,7 +21,7 @@ namespace ui { // designed as a replacement for the Win32's SetProp, but does not make use of // window manager memory. ViewProp shares similar semantics as SetProp, the // value for a particular view/key pair comes from the last ViewProp created. -class UI_BASE_EXPORT ViewProp { +class COMPONENT_EXPORT(UI_BASE) ViewProp { public: // Associates data with a view/key pair. If a ViewProp has already been // created for the specified pair |data| replaces the current value. diff --git a/chromium/ui/base/webui/i18n_source_stream.h b/chromium/ui/base/webui/i18n_source_stream.h index 994ac6ce4ba..bba7a13c27e 100644 --- a/chromium/ui/base/webui/i18n_source_stream.h +++ b/chromium/ui/base/webui/i18n_source_stream.h @@ -8,14 +8,15 @@ #include #include +#include "base/component_export.h" #include "base/macros.h" #include "net/filter/filter_source_stream.h" #include "ui/base/template_expressions.h" -#include "ui/base/ui_base_export.h" namespace ui { -class UI_BASE_EXPORT I18nSourceStream : public net::FilterSourceStream { +class COMPONENT_EXPORT(UI_BASE) I18nSourceStream + : public net::FilterSourceStream { public: ~I18nSourceStream() override; diff --git a/chromium/ui/base/webui/jstemplate_builder.cc b/chromium/ui/base/webui/jstemplate_builder.cc index b2b2b142275..50c52507d00 100644 --- a/chromium/ui/base/webui/jstemplate_builder.cc +++ b/chromium/ui/base/webui/jstemplate_builder.cc @@ -123,7 +123,7 @@ void AppendJsonJS(const base::DictionaryValue* json, // If the script is being imported as a module, import |loadTimeData| in // order to allow assigning the localized strings to loadTimeData.data. output->append("import {loadTimeData} from "); - output->append("'chrome://resources/js/load_time_data.m.js';\n"); + output->append("'//resources/js/load_time_data.m.js';\n"); } std::string jstext; diff --git a/chromium/ui/base/webui/jstemplate_builder.h b/chromium/ui/base/webui/jstemplate_builder.h index 5b1c1170690..97a4a558a2d 100644 --- a/chromium/ui/base/webui/jstemplate_builder.h +++ b/chromium/ui/base/webui/jstemplate_builder.h @@ -15,8 +15,8 @@ #include +#include "base/component_export.h" #include "base/strings/string_piece.h" -#include "ui/base/ui_base_export.h" namespace base { class DictionaryValue; @@ -27,22 +27,23 @@ namespace webui { // A helper function that generates a string of HTML to be loaded. The // string includes the HTML and the javascript code necessary to generate the // full page with support for i18n Templates. -UI_BASE_EXPORT std::string GetI18nTemplateHtml( - const base::StringPiece& html_template, - const base::DictionaryValue* json); +COMPONENT_EXPORT(UI_BASE) +std::string GetI18nTemplateHtml(const base::StringPiece& html_template, + const base::DictionaryValue* json); // A helper function that generates a string of HTML to be loaded. The // string includes the HTML and the javascript code necessary to generate the // full page with support for both i18n Templates and JsTemplates. -UI_BASE_EXPORT std::string GetTemplatesHtml( - const base::StringPiece& html_template, - const base::DictionaryValue* json, - const base::StringPiece& template_id); +COMPONENT_EXPORT(UI_BASE) +std::string GetTemplatesHtml(const base::StringPiece& html_template, + const base::DictionaryValue* json, + const base::StringPiece& template_id); // Assigns the given json data into |loadTimeData|, without a