diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-05-20 09:47:09 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-06-07 11:15:42 +0000 |
commit | 189d4fd8fad9e3c776873be51938cd31a42b6177 (patch) | |
tree | 6497caeff5e383937996768766ab3bb2081a40b2 /chromium/components/remote_cocoa | |
parent | 8bc75099d364490b22f43a7ce366b366c08f4164 (diff) | |
download | qtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz |
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/remote_cocoa')
14 files changed, 214 insertions, 41 deletions
diff --git a/chromium/components/remote_cocoa/DIR_METADATA b/chromium/components/remote_cocoa/DIR_METADATA new file mode 100644 index 00000000000..f573c6521eb --- /dev/null +++ b/chromium/components/remote_cocoa/DIR_METADATA @@ -0,0 +1,3 @@ +monorail { + component: "Internals>Views" +} diff --git a/chromium/components/remote_cocoa/OWNERS b/chromium/components/remote_cocoa/OWNERS index 0e3699ba54d..f2380872378 100644 --- a/chromium/components/remote_cocoa/OWNERS +++ b/chromium/components/remote_cocoa/OWNERS @@ -1,3 +1 @@ file://ui/views/cocoa/OWNERS - -# COMPONENT: Internals>Views diff --git a/chromium/components/remote_cocoa/app_shim/BUILD.gn b/chromium/components/remote_cocoa/app_shim/BUILD.gn index a9bf35e0cdd..83ec5244b1d 100644 --- a/chromium/components/remote_cocoa/app_shim/BUILD.gn +++ b/chromium/components/remote_cocoa/app_shim/BUILD.gn @@ -67,6 +67,7 @@ component("app_shim") { "//ui/base/ime:ime", "//ui/events", "//ui/gfx", + "//ui/gfx/geometry", "//ui/strings:ui_strings_grit", ] frameworks = [ diff --git a/chromium/components/remote_cocoa/app_shim/bridged_content_view.mm b/chromium/components/remote_cocoa/app_shim/bridged_content_view.mm index d277717b7cd..ec3c92fe8d3 100644 --- a/chromium/components/remote_cocoa/app_shim/bridged_content_view.mm +++ b/chromium/components/remote_cocoa/app_shim/bridged_content_view.mm @@ -129,7 +129,7 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { // editing command from ui_strings.grd and, when not being sent to a // TextInputClient, the keyCode that toolkit-views expects internally. // For example, moveToLeftEndOfLine: would pass ui::VKEY_HOME in non-RTL locales -// even though the Home key on Mac defaults to moveToBeginningOfDocument:. +// even though the Home key on Mac defaults to scrollToBeginningOfDocument:. // This approach also allows action messages a user // may have remapped in ~/Library/KeyBindings/DefaultKeyBinding.dict to be // catered for. @@ -911,16 +911,16 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { - (void)moveToBeginningOfLine:(id)sender { [self handleAction:ui::TextEditCommand::MOVE_TO_BEGINNING_OF_LINE - keyCode:ui::VKEY_HOME - domCode:ui::DomCode::HOME - eventFlags:0]; + keyCode:ui::VKEY_LEFT + domCode:ui::DomCode::ARROW_LEFT + eventFlags:ui::EF_COMMAND_DOWN]; } - (void)moveToEndOfLine:(id)sender { [self handleAction:ui::TextEditCommand::MOVE_TO_END_OF_LINE - keyCode:ui::VKEY_END - domCode:ui::DomCode::END - eventFlags:0]; + keyCode:ui::VKEY_RIGHT + domCode:ui::DomCode::ARROW_RIGHT + eventFlags:ui::EF_COMMAND_DOWN]; } - (void)moveToBeginningOfParagraph:(id)sender { @@ -939,16 +939,16 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { - (void)moveToEndOfDocument:(id)sender { [self handleAction:ui::TextEditCommand::MOVE_TO_END_OF_DOCUMENT - keyCode:ui::VKEY_END - domCode:ui::DomCode::END - eventFlags:ui::EF_CONTROL_DOWN]; + keyCode:ui::VKEY_DOWN + domCode:ui::DomCode::ARROW_DOWN + eventFlags:ui::EF_COMMAND_DOWN]; } - (void)moveToBeginningOfDocument:(id)sender { [self handleAction:ui::TextEditCommand::MOVE_TO_BEGINNING_OF_DOCUMENT - keyCode:ui::VKEY_HOME - domCode:ui::DomCode::HOME - eventFlags:ui::EF_CONTROL_DOWN]; + keyCode:ui::VKEY_UP + domCode:ui::DomCode::ARROW_UP + eventFlags:ui::EF_COMMAND_DOWN]; } - (void)pageDown:(id)sender { @@ -1151,6 +1151,34 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) { : [self moveToEndOfLineAndModifySelection:sender]; } +- (void)scrollPageDown:(id)sender { + [self handleAction:ui::TextEditCommand::SCROLL_PAGE_DOWN + keyCode:ui::VKEY_NEXT + domCode:ui::DomCode::PAGE_DOWN + eventFlags:ui::EF_NONE]; +} + +- (void)scrollPageUp:(id)sender { + [self handleAction:ui::TextEditCommand::SCROLL_PAGE_UP + keyCode:ui::VKEY_PRIOR + domCode:ui::DomCode::PAGE_UP + eventFlags:ui::EF_NONE]; +} + +- (void)scrollToBeginningOfDocument:(id)sender { + [self handleAction:ui::TextEditCommand::SCROLL_TO_BEGINNING_OF_DOCUMENT + keyCode:ui::VKEY_HOME + domCode:ui::DomCode::HOME + eventFlags:ui::EF_NONE]; +} + +- (void)scrollToEndOfDocument:(id)sender { + [self handleAction:ui::TextEditCommand::SCROLL_TO_END_OF_DOCUMENT + keyCode:ui::VKEY_END + domCode:ui::DomCode::END + eventFlags:ui::EF_NONE]; +} + // Graphical Element transposition - (void)transpose:(id)sender { diff --git a/chromium/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm b/chromium/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm index 5e5a39c2920..44a574ee1a1 100644 --- a/chromium/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm +++ b/chromium/components/remote_cocoa/app_shim/native_widget_mac_nswindow.mm @@ -19,10 +19,6 @@ - (BOOL)hasKeyAppearance; - (long long)_resizeDirectionForMouseLocation:(CGPoint)location; - (BOOL)_isConsideredOpenForPersistentState; - -// Available in later point releases of 10.10. On 10.11+, use the public -// -performWindowDragWithEvent: instead. -- (void)beginWindowDragWithEvent:(NSEvent*)event; @end @interface NativeWidgetMacNSWindow () <NSKeyedArchiverDelegate> @@ -47,13 +43,7 @@ if ([self.window _resizeDirectionForMouseLocation:event.locationInWindow] != -1) return; - if (@available(macOS 10.11, *)) - [self.window performWindowDragWithEvent:event]; - else if ([self.window - respondsToSelector:@selector(beginWindowDragWithEvent:)]) - [self.window beginWindowDragWithEvent:event]; - else - NOTREACHED(); + [self.window performWindowDragWithEvent:event]; } @end diff --git a/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h b/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h index 7068e5d2d82..40ef7d7dd6b 100644 --- a/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h +++ b/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h @@ -208,7 +208,7 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge void ShowEmojiPanel() override; void InitWindow( remote_cocoa::mojom::NativeWidgetNSWindowInitParamsPtr params) override; - void InitCompositorView() override; + void InitCompositorView(InitCompositorViewCallback callback) override; void CreateContentView(uint64_t ns_view_id, const gfx::Rect& bounds) override; void DestroyContentView() override; void CloseWindow() override; @@ -235,7 +235,7 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge bool is_maximizable) override; void SetOpacity(float opacity) override; void SetWindowLevel(int32_t level) override; - void SetContentAspectRatio(const gfx::SizeF& aspect_ratio) override; + void SetAspectRatio(const gfx::SizeF& aspect_ratio) override; void SetCALayerParams(const gfx::CALayerParams& ca_layer_params) override; void SetWindowTitle(const base::string16& title) override; void SetIgnoresMouseEvents(bool ignores_mouse_events) override; diff --git a/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm b/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm index cad39d6496a..93db386ed8e 100644 --- a/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm +++ b/chromium/components/remote_cocoa/app_shim/native_widget_ns_window_bridge.mm @@ -1028,7 +1028,8 @@ void NativeWidgetNSWindowBridge::OnShowAnimationComplete() { show_animation_.reset(); } -void NativeWidgetNSWindowBridge::InitCompositorView() { +void NativeWidgetNSWindowBridge::InitCompositorView( + InitCompositorViewCallback callback) { // Use the regular window background for window modal sheets. The layer will // still paint over most of it, but the native -[NSApp beginSheet:] animation // blocks the UI thread, so there's no way to invalidate the shadow to match @@ -1053,6 +1054,9 @@ void NativeWidgetNSWindowBridge::InitCompositorView() { // will be forwarded. UpdateWindowDisplay(); UpdateWindowGeometry(); + + // Inform the browser of the CGWindowID for this NSWindow. + std::move(callback).Run([window_ windowNumber]); } void NativeWidgetNSWindowBridge::SortSubviews( @@ -1223,10 +1227,11 @@ void NativeWidgetNSWindowBridge::SetWindowLevel(int32_t level) { [window_ setCollectionBehavior:behavior]; } -void NativeWidgetNSWindowBridge::SetContentAspectRatio( +void NativeWidgetNSWindowBridge::SetAspectRatio( const gfx::SizeF& aspect_ratio) { - [window_ setContentAspectRatio:NSMakeSize(aspect_ratio.width(), - aspect_ratio.height())]; + DCHECK(!aspect_ratio.IsEmpty()); + [window_delegate_ + setAspectRatio:aspect_ratio.width() / aspect_ratio.height()]; } void NativeWidgetNSWindowBridge::SetCALayerParams( diff --git a/chromium/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm b/chromium/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm index a621a83f294..fe2caaf84fb 100644 --- a/chromium/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm +++ b/chromium/components/remote_cocoa/app_shim/select_file_dialog_bridge.mm @@ -13,6 +13,7 @@ #include "base/mac/scoped_cftyperef.h" #include "base/strings/sys_string_conversions.h" #include "base/strings/utf_string_conversions.h" +#include "base/threading/thread_restrictions.h" #import "ui/base/cocoa/controls/textfield_utils.h" #include "ui/base/l10n/l10n_util_mac.h" #include "ui/strings/grit/ui_strings.h" @@ -320,7 +321,7 @@ void SelectFileDialogBridge::SetAccessoryView( // Populate file_type_lists. // Set to store different extensions in the current extension group. - NSMutableSet* file_type_set = [NSMutableSet set]; + NSMutableArray* file_type_array = [NSMutableArray array]; for (const base::FilePath::StringType& ext : ext_list) { if (ext == default_extension) default_extension_index = i; @@ -329,8 +330,11 @@ void SelectFileDialogBridge::SetAccessoryView( // we nil check before adding to |file_type_set|. See crbug.com/630101 and // rdar://27490414. base::ScopedCFTypeRef<CFStringRef> uti(CreateUTIFromExtension(ext)); - if (uti) - [file_type_set addObject:base::mac::CFToNSCast(uti.get())]; + if (uti) { + NSString* uti_ns = base::mac::CFToNSCast(uti.get()); + if (![file_type_array containsObject:uti_ns]) + [file_type_array addObject:uti_ns]; + } // Always allow the extension itself, in case the UTI doesn't map // back to the original extension correctly. This occurs with dynamic @@ -338,9 +342,11 @@ void SelectFileDialogBridge::SetAccessoryView( // See http://crbug.com/148840, http://openradar.me/12316273 base::ScopedCFTypeRef<CFStringRef> ext_cf( base::SysUTF8ToCFStringRef(ext)); - [file_type_set addObject:base::mac::CFToNSCast(ext_cf.get())]; + NSString* ext_ns = base::mac::CFToNSCast(ext_cf.get()); + if (![file_type_array containsObject:ext_ns]) + [file_type_array addObject:ext_ns]; } - [file_type_lists addObject:[file_type_set allObjects]]; + [file_type_lists addObject:file_type_array]; } if (file_types->include_all_files || file_types->extensions.empty()) { diff --git a/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.h b/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.h index a18e18610ee..93fefce9db7 100644 --- a/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.h +++ b/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.h @@ -8,6 +8,7 @@ #import <Cocoa/Cocoa.h> #import "base/mac/scoped_nsobject.h" +#include "base/optional.h" #include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h" namespace remote_cocoa { @@ -21,6 +22,19 @@ REMOTE_COCOA_APP_SHIM_EXPORT @private remote_cocoa::NativeWidgetNSWindowBridge* _parent; // Weak. Owns this. base::scoped_nsobject<NSCursor> _cursor; + base::Optional<float> _aspectRatio; + + // Only valid during a live resize. + // Used to keep track of whether a resize is happening horizontally or + // vertically, even if physically the user is resizing in both directions. + // The value is significant when |_aspectRatio| is set, i.e., we are + // responsible for maintaining the aspect ratio of the window. As the user is + // dragging one of the corners to resize, we need the resize to be either + // horizontal or vertical all the time, so we pick one of the directions and + // stick to it. This is necessary to achieve stable results, because in order + // to keep the aspect ratio fixed we override one window dimension with a + // value computed from the other dimension. + base::Optional<bool> _resizingHorizontally; } // If set, the cursor set in -[NSResponder updateCursor:] when the window is @@ -46,6 +60,14 @@ REMOTE_COCOA_APP_SHIM_EXPORT returnCode:(NSInteger)returnCode contextInfo:(void*)contextInfo; +// Set the aspect ratio of the window. Window resizes will be constrained in an +// attempt to maintain the aspect ratio. +// Cocoa provides this functionality via the [NSWindow aspectRatio] property, +// but its implementation prioritizes the aspect ratio over the minimum size: +// one of the dimensions can go below the minimum size if that's what it takes +// to maintain the aspect ratio. This is inacceptable for us. +- (void)setAspectRatio:(float)aspectRatio; + @end #endif // COMPONENTS_REMOTE_COCOA_APP_SHIM_VIEWS_NSWINDOW_DELEGATE_H_ diff --git a/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.mm b/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.mm index f62001198b6..36239594f91 100644 --- a/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.mm +++ b/chromium/components/remote_cocoa/app_shim/views_nswindow_delegate.mm @@ -7,11 +7,13 @@ #include "base/bind.h" #include "base/check.h" #include "base/mac/mac_util.h" +#include "base/numerics/ranges.h" #include "base/threading/thread_task_runner_handle.h" #import "components/remote_cocoa/app_shim/bridged_content_view.h" #import "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h" #include "components/remote_cocoa/app_shim/native_widget_ns_window_host_helper.h" #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h" +#include "ui/gfx/geometry/resize_utils.h" @implementation ViewsNSWindowDelegate @@ -101,6 +103,35 @@ DCHECK(!_parent->target_fullscreen_state()); } +- (void)setAspectRatio:(float)aspectRatio { + _aspectRatio = aspectRatio; +} + +- (NSSize)windowWillResize:(NSWindow*)window toSize:(NSSize)size { + if (!_aspectRatio) + return size; + + if (!_resizingHorizontally) { + const auto widthDelta = size.width - [window frame].size.width; + const auto heightDelta = size.height - [window frame].size.height; + _resizingHorizontally = std::abs(widthDelta) > std::abs(heightDelta); + } + + gfx::Rect resizedWindowRect(gfx::Point([window frame].origin), + gfx::Size(size)); + gfx::SizeRectToAspectRatio(*_resizingHorizontally ? gfx::ResizeEdge::kRight + : gfx::ResizeEdge::kBottom, + *_aspectRatio, gfx::Size([window minSize]), + gfx::Size([window maxSize]), &resizedWindowRect); + // Discard any updates to |resizedWindowRect| origin as Cocoa takes care of + // that. + return resizedWindowRect.size().ToCGSize(); +} + +- (void)windowDidEndLiveResize:(NSNotification*)notification { + _resizingHorizontally.reset(); +} + - (void)windowDidResize:(NSNotification*)notification { _parent->OnSizeChanged(); } diff --git a/chromium/components/remote_cocoa/browser/BUILD.gn b/chromium/components/remote_cocoa/browser/BUILD.gn index 6b948b93457..a8da669ab69 100644 --- a/chromium/components/remote_cocoa/browser/BUILD.gn +++ b/chromium/components/remote_cocoa/browser/BUILD.gn @@ -14,6 +14,8 @@ component("browser") { "ns_view_ids.cc", "ns_view_ids.h", "remote_cocoa_browser_export.h", + "scoped_cg_window_id.cc", + "scoped_cg_window_id.h", "window.h", "window.mm", ] @@ -21,6 +23,7 @@ component("browser") { deps = [ "//base", "//components/remote_cocoa/common:mojo", + "//components/viz/common:common", "//mojo/public/cpp/bindings:bindings", "//ui/gfx", ] diff --git a/chromium/components/remote_cocoa/browser/scoped_cg_window_id.cc b/chromium/components/remote_cocoa/browser/scoped_cg_window_id.cc new file mode 100644 index 00000000000..8ff016065c5 --- /dev/null +++ b/chromium/components/remote_cocoa/browser/scoped_cg_window_id.cc @@ -0,0 +1,45 @@ +// Copyright 2021 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 "components/remote_cocoa/browser/scoped_cg_window_id.h" + +#include <map> + +#include "base/no_destructor.h" + +namespace remote_cocoa { + +namespace { + +using ScoperMap = std::map<uint32_t, ScopedCGWindowID*>; + +ScoperMap& GetMap() { + static base::NoDestructor<ScoperMap> map; + return *map.get(); +} + +} // namespace + +ScopedCGWindowID::ScopedCGWindowID(uint32_t cg_window_id, + const viz::FrameSinkId& frame_sink_id) + : cg_window_id_(cg_window_id), frame_sink_id_(frame_sink_id) { + DCHECK_EQ(GetMap().count(cg_window_id), 0u); + GetMap()[cg_window_id] = this; +} + +ScopedCGWindowID::~ScopedCGWindowID() { + auto found = GetMap().find(cg_window_id_); + DCHECK_EQ(found->second, this); + GetMap().erase(found); +} + +// static +ScopedCGWindowID* ScopedCGWindowID::Get(uint32_t cg_window_id) { + auto found = GetMap().find(cg_window_id); + if (found == GetMap().end()) + return nullptr; + return found->second; +} + +} // namespace remote_cocoa diff --git a/chromium/components/remote_cocoa/browser/scoped_cg_window_id.h b/chromium/components/remote_cocoa/browser/scoped_cg_window_id.h new file mode 100644 index 00000000000..54bfca37faa --- /dev/null +++ b/chromium/components/remote_cocoa/browser/scoped_cg_window_id.h @@ -0,0 +1,40 @@ +// Copyright 2021 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 COMPONENTS_REMOTE_COCOA_BROWSER_SCOPED_CG_WINDOW_ID_H_ +#define COMPONENTS_REMOTE_COCOA_BROWSER_SCOPED_CG_WINDOW_ID_H_ + +#include <stdint.h> + +#include "components/remote_cocoa/browser/remote_cocoa_browser_export.h" +#include "components/viz/common/surfaces/frame_sink_id.h" + +namespace remote_cocoa { + +// A registry of the CGWindowIDs for the remote cocoa windows created in any +// process (the browser and also the renderer). This can be used to look up +// the compositing frame sink id for efficient video capture. +class REMOTE_COCOA_BROWSER_EXPORT ScopedCGWindowID { + public: + ScopedCGWindowID(uint32_t cg_window_id, + const viz::FrameSinkId& frame_sink_id); + ~ScopedCGWindowID(); + ScopedCGWindowID(const ScopedCGWindowID&) = delete; + ScopedCGWindowID& operator=(const ScopedCGWindowID&) = delete; + + // Query the frame sink id for this window, which can be used for optimized + // video capture. + const viz::FrameSinkId& GetFrameSinkId() const { return frame_sink_id_; } + + // Look up this structure corresponding to a given CGWindowID. + static ScopedCGWindowID* Get(uint32_t cg_window_id); + + private: + const uint32_t cg_window_id_; + const viz::FrameSinkId frame_sink_id_; +}; + +} // namespace remote_cocoa + +#endif // COMPONENTS_REMOTE_COCOA_BROWSER_SCOPED_CG_WINDOW_ID_H_ diff --git a/chromium/components/remote_cocoa/common/native_widget_ns_window.mojom b/chromium/components/remote_cocoa/common/native_widget_ns_window.mojom index b3dea656465..1a8b77dab65 100644 --- a/chromium/components/remote_cocoa/common/native_widget_ns_window.mojom +++ b/chromium/components/remote_cocoa/common/native_widget_ns_window.mojom @@ -109,8 +109,9 @@ interface NativeWidgetNSWindow { // Initialize the view to display compositor output. This will send the // current visibility and dimensions (and any future updates) to the - // NativeWidgetNSWindowHost. - InitCompositorView(); + // NativeWidgetNSWindowHost. Returns the CGWindowID to associate with + // the compositor's FrameSinkId. + InitCompositorView() => (uint32 cg_window_id); // Create the NSView to be the content view for the window. Use |ns_view_id| // to look up this NSView in other functions (e.g, to specify a parent view). @@ -186,8 +187,8 @@ interface NativeWidgetNSWindow { // Set the window level of the NSWindow. SetWindowLevel(int32 level); - // Set the content aspect ratio of the NSWindow. - SetContentAspectRatio(gfx.mojom.SizeF aspect_ratio); + // Set the aspect ratio of the NSWindow. |aspect_ratio| must not be empty. + SetAspectRatio(gfx.mojom.SizeF aspect_ratio); // Specify the content to draw in the NSView. SetCALayerParams(gfx.mojom.CALayerParams ca_layer_params); |