cef/patch/patches/views_widget_180_1481_1565_...

433 lines
18 KiB
Diff

diff --git content/browser/renderer_host/render_widget_host_view_base.cc content/browser/renderer_host/render_widget_host_view_base.cc
index 85b265f70047..691e04ddcf97 100644
--- content/browser/renderer_host/render_widget_host_view_base.cc
+++ content/browser/renderer_host/render_widget_host_view_base.cc
@@ -565,6 +565,14 @@ float RenderWidgetHostViewBase::GetDeviceScaleFactor() {
return screen_info.device_scale_factor;
}
+void RenderWidgetHostViewBase::SetHasExternalParent(bool val) {
+ has_external_parent_ = val;
+}
+
+bool RenderWidgetHostViewBase::HasExternalParent() const {
+ return has_external_parent_;
+}
+
uint32_t RenderWidgetHostViewBase::RendererFrameNumber() {
return renderer_frame_number_;
}
diff --git content/browser/renderer_host/render_widget_host_view_base.h content/browser/renderer_host/render_widget_host_view_base.h
index d6363c75664b..45288fdafdee 100644
--- content/browser/renderer_host/render_widget_host_view_base.h
+++ content/browser/renderer_host/render_widget_host_view_base.h
@@ -66,6 +66,7 @@ class CursorManager;
class MouseWheelPhaseHandler;
class RenderWidgetHostImpl;
class RenderWidgetHostViewBaseObserver;
+class RenderWidgetHostViewGuest;
class SyntheticGestureTarget;
class TextInputManager;
class TouchSelectionControllerClientManager;
@@ -83,6 +84,9 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
float current_device_scale_factor() const {
return current_device_scale_factor_;
}
+ void set_current_device_scale_factor(float scale_factor) {
+ current_device_scale_factor_ = scale_factor;
+ }
// Returns the focused RenderWidgetHost inside this |view|'s RWH.
RenderWidgetHostImpl* GetFocusedWidget() const;
@@ -117,6 +121,8 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
void DisableAutoResize(const gfx::Size& new_size) override;
bool IsScrollOffsetAtTop() override;
float GetDeviceScaleFactor() final;
+ void SetHasExternalParent(bool val) override;
+ bool HasExternalParent() const override;
TouchSelectionControllerClientManager*
GetTouchSelectionControllerClientManager() override;
void SetRecordContentToVisibleTimeRequest(
@@ -439,6 +445,12 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
// helps to position the full screen widget on the correct monitor.
virtual void InitAsFullscreen(RenderWidgetHostView* reference_host_view) = 0;
+ // Perform all the initialization steps necessary for this object to represent
+ // the platform widget owned by |guest_view| and embedded in
+ // |parent_host_view|.
+ virtual void InitAsGuest(RenderWidgetHostView* parent_host_view,
+ RenderWidgetHostViewGuest* guest_view) {}
+
// Sets the cursor for this view to the one associated with the specified
// cursor_type.
virtual void UpdateCursor(const WebCursor& cursor) = 0;
@@ -616,6 +628,10 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
// specific RenderWidgetHostView.
base::Optional<DisplayFeature> display_feature_;
+ // True if the widget has a external parent view/window outside of the
+ // Chromium-controlled view/window hierarchy.
+ bool has_external_parent_ = false;
+
private:
FRIEND_TEST_ALL_PREFIXES(
BrowserSideFlingBrowserTest,
diff --git content/browser/renderer_host/render_widget_host_view_event_handler.cc content/browser/renderer_host/render_widget_host_view_event_handler.cc
index df6f607a65ae..e37f7bf73f0f 100644
--- content/browser/renderer_host/render_widget_host_view_event_handler.cc
+++ content/browser/renderer_host/render_widget_host_view_event_handler.cc
@@ -34,6 +34,10 @@
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/touch_selection/touch_selection_controller.h"
+#if defined(OS_LINUX)
+#include "ui/aura/window_tree_host.h"
+#endif
+
#if defined(OS_WIN)
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "ui/aura/window_tree_host.h"
@@ -931,6 +935,14 @@ void RenderWidgetHostViewEventHandler::SetKeyboardFocus() {
::SetFocus(hwnd);
}
}
+#endif
+#if defined(OS_LINUX)
+ if (host_view_->HasExternalParent() &&
+ window_ && window_->delegate()->CanFocus()) {
+ aura::WindowTreeHost* host = window_->GetHost();
+ if (host)
+ host->Show();
+ }
#endif
// TODO(wjmaclean): can host_ ever be null?
if (host_ && set_focus_on_mouse_down_or_key_event_) {
diff --git content/public/browser/render_widget_host_view.h content/public/browser/render_widget_host_view.h
index 4810a45aa4b0..33e32192f975 100644
--- content/public/browser/render_widget_host_view.h
+++ content/public/browser/render_widget_host_view.h
@@ -243,6 +243,14 @@ class CONTENT_EXPORT RenderWidgetHostView {
// This must always return the same device scale factor as GetScreenInfo.
virtual float GetDeviceScaleFactor() = 0;
+ // Set whether the widget has a external parent view/window outside of the
+ // Chromium-controlled view/window hierarchy.
+ virtual void SetHasExternalParent(bool val) = 0;
+
+ // Returns true if the widget has a external parent view/window outside of the
+ // Chromium-controlled view/window hierarchy.
+ virtual bool HasExternalParent() const = 0;
+
#if defined(OS_MACOSX)
// Set the view's active state (i.e., tint state of controls).
virtual void SetActive(bool active) = 0;
diff --git ui/base/x/x11_window.cc ui/base/x/x11_window.cc
index bc5f4fefa7a0..4b2e110441be 100644
--- ui/base/x/x11_window.cc
+++ ui/base/x/x11_window.cc
@@ -270,7 +270,8 @@ void XWindow::Init(const Configuration& config) {
req.border_pixel = 0;
bounds_in_pixels_ = SanitizeBounds(config.bounds);
- req.parent = x_root_window_;
+ req.parent = config.parent_widget == gfx::kNullAcceleratedWidget ?
+ x_root_window_ : config.parent_widget;
req.x = bounds_in_pixels_.x();
req.y = bounds_in_pixels_.y();
req.width = bounds_in_pixels_.width();
diff --git ui/base/x/x11_window.h ui/base/x/x11_window.h
index c5b0d7227a5d..69d4f6013f3d 100644
--- ui/base/x/x11_window.h
+++ ui/base/x/x11_window.h
@@ -20,6 +20,7 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_f.h"
+#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/x/event.h"
#include "ui/gfx/x/sync.h"
#include "ui/gfx/x/x11.h"
@@ -91,6 +92,7 @@ class COMPONENT_EXPORT(UI_BASE_X) XWindow {
std::string wm_class_name;
std::string wm_class_class;
std::string wm_role_name;
+ gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget;
};
XWindow();
diff --git ui/platform_window/x11/x11_window.cc ui/platform_window/x11/x11_window.cc
index bc2c18233b75..4e2f72b51cdf 100644
--- ui/platform_window/x11/x11_window.cc
+++ ui/platform_window/x11/x11_window.cc
@@ -97,6 +97,7 @@ ui::XWindow::Configuration ConvertInitPropertiesToXWindowConfig(
config.wm_class_class = properties.wm_class_class;
config.wm_role_name = properties.wm_role_name;
config.activatable = properties.activatable;
+ config.parent_widget = properties.parent_widget;
config.prefer_dark_theme = properties.prefer_dark_theme;
config.background_color = properties.background_color;
return config;
diff --git ui/views/widget/desktop_aura/desktop_screen_win.cc ui/views/widget/desktop_aura/desktop_screen_win.cc
index e9bb45ad238c..68f2a5ef5d0c 100644
--- ui/views/widget/desktop_aura/desktop_screen_win.cc
+++ ui/views/widget/desktop_aura/desktop_screen_win.cc
@@ -18,6 +18,8 @@ DesktopScreenWin::~DesktopScreenWin() {
}
HWND DesktopScreenWin::GetHWNDFromNativeWindow(gfx::NativeWindow window) const {
+ if (!window)
+ return nullptr;
aura::WindowTreeHost* host = window->GetHost();
return host ? host->GetAcceleratedWidget() : nullptr;
}
diff --git ui/views/widget/desktop_aura/desktop_window_tree_host_linux.cc ui/views/widget/desktop_aura/desktop_window_tree_host_linux.cc
index 61d8b3a06783..7f9552f2b36b 100644
--- ui/views/widget/desktop_aura/desktop_window_tree_host_linux.cc
+++ ui/views/widget/desktop_aura/desktop_window_tree_host_linux.cc
@@ -315,6 +315,8 @@ void DesktopWindowTreeHostLinux::AddAdditionalInitProperties(
properties->wm_class_class = params.wm_class_class;
properties->wm_role_name = params.wm_role_name;
+ properties->parent_widget = params.parent_widget;
+
DCHECK(!properties->x11_extension_delegate);
properties->x11_extension_delegate = this;
}
diff --git ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
index b5430b871cfc..f0d5d8521e4b 100644
--- ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
+++ ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
@@ -140,8 +140,12 @@ void DesktopWindowTreeHostWin::Init(const Widget::InitParams& params) {
native_widget_delegate_);
HWND parent_hwnd = nullptr;
- if (params.parent && params.parent->GetHost())
+ if (params.parent_widget) {
+ parent_hwnd = params.parent_widget;
+ has_external_parent_ = true;
+ } else if (params.parent && params.parent->GetHost()) {
parent_hwnd = params.parent->GetHost()->GetAcceleratedWidget();
+ }
remove_standard_frame_ = params.remove_standard_frame;
has_non_client_view_ = Widget::RequiresNonClientView(params.type);
@@ -918,11 +922,15 @@ void DesktopWindowTreeHostWin::HandleFrameChanged() {
}
void DesktopWindowTreeHostWin::HandleNativeFocus(HWND last_focused_window) {
- // TODO(beng): inform the native_widget_delegate_.
+ // See comments in CefBrowserHostImpl::PlatformSetFocus.
+ if (has_external_parent_ && CanActivate())
+ HandleActivationChanged(true);
}
void DesktopWindowTreeHostWin::HandleNativeBlur(HWND focused_window) {
- // TODO(beng): inform the native_widget_delegate_.
+ // See comments in CefBrowserHostImpl::PlatformSetFocus.
+ if (has_external_parent_ && CanActivate())
+ HandleActivationChanged(false);
}
bool DesktopWindowTreeHostWin::HandleMouseEvent(ui::MouseEvent* event) {
diff --git ui/views/widget/desktop_aura/desktop_window_tree_host_win.h ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
index c0f00b6d86d3..0a4da77de31a 100644
--- ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
+++ ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
@@ -294,6 +294,10 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
// True if the window should have the frame removed.
bool remove_standard_frame_;
+ // True if the widget has a external parent view/window outside of the
+ // Chromium-controlled view/window hierarchy.
+ bool has_external_parent_ = false;
+
// Owned by TooltipController, but we need to forward events to it so we keep
// a reference.
corewm::TooltipWin* tooltip_;
diff --git ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index af81a254b0ce..42474f1e7c1e 100644
--- ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -78,6 +78,9 @@ DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() = default;
// DesktopWindowTreeHostX11, DesktopWindowTreeHost implementation:
void DesktopWindowTreeHostX11::Init(const Widget::InitParams& params) {
+ if (params.parent_widget != gfx::kNullAcceleratedWidget)
+ has_external_parent_ = true;
+
DesktopWindowTreeHostLinux::Init(params);
// Set XEventDelegate to receive selection, drag&drop and raw key events.
@@ -101,6 +104,18 @@ DesktopWindowTreeHostX11::CreateDragDropClient(
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11 implementation:
+gfx::Rect DesktopWindowTreeHostX11::GetWindowBoundsInScreen() const {
+ if (!screen_bounds_.IsEmpty())
+ return screen_bounds_;
+ return DesktopWindowTreeHostLinux::GetWindowBoundsInScreen();
+}
+
+gfx::Point DesktopWindowTreeHostX11::GetLocationOnScreenInPixels() const {
+ if (!screen_bounds_.IsEmpty())
+ return screen_bounds_.origin();
+ return DesktopWindowTreeHostLinux::GetLocationOnScreenInPixels();
+}
+
void DesktopWindowTreeHostX11::OnXWindowSelectionEvent(x11::Event* xev) {
DCHECK(xev);
DCHECK(drag_drop_client_);
diff --git ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h
index 695019454640..9d85e934f6e5 100644
--- ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h
+++ ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h
@@ -31,12 +31,21 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
DesktopNativeWidgetAura* desktop_native_widget_aura);
~DesktopWindowTreeHostX11() override;
+ void set_screen_bounds(const gfx::Rect& bounds) { screen_bounds_ = bounds; }
+
+ // Returns true if the widget has a external parent view/window outside of the
+ // Chromium-controlled view/window hierarchy.
+ bool has_external_parent() const { return has_external_parent_; }
+
protected:
// Overridden from DesktopWindowTreeHost:
void Init(const Widget::InitParams& params) override;
std::unique_ptr<aura::client::DragDropClient> CreateDragDropClient(
DesktopNativeCursorManager* cursor_manager) override;
+ gfx::Rect GetWindowBoundsInScreen() const override;
+ gfx::Point GetLocationOnScreenInPixels() const override;
+
private:
friend class DesktopWindowTreeHostX11HighDPITest;
@@ -50,8 +59,18 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 : public DesktopWindowTreeHostLinux,
// directly. See https://crbug.com/990756.
const ui::XWindow* GetXWindow() const;
+ // Override the screen bounds when the host is a child window.
+ gfx::Rect screen_bounds_;
+
+ // True if the widget has a external parent view/window outside of the
+ // Chromium-controlled view/window hierarchy.
+ bool has_external_parent_ = false;
+
DesktopDragDropClientAuraX11* drag_drop_client_ = nullptr;
+ // True if the xwindow has already been destroyed.
+ bool xwindow_destroyed_ = false;
+
DISALLOW_COPY_AND_ASSIGN(DesktopWindowTreeHostX11);
};
diff --git ui/views/widget/widget.cc ui/views/widget/widget.cc
index a06ebe82c33f..559ec6d0130d 100644
--- ui/views/widget/widget.cc
+++ ui/views/widget/widget.cc
@@ -285,7 +285,8 @@ void Widget::Init(InitParams params) {
params.name = params.delegate->GetContentsView()->GetClassName();
params.child |= (params.type == InitParams::TYPE_CONTROL);
- is_top_level_ = !params.child;
+ is_top_level_ = !params.child ||
+ params.parent_widget != gfx::kNullAcceleratedWidget;
if (params.opacity == views::Widget::InitParams::WindowOpacity::kInferred &&
params.type != views::Widget::InitParams::TYPE_WINDOW) {
@@ -369,7 +370,12 @@ void Widget::Init(InitParams params) {
}
} else if (delegate) {
SetContentsView(delegate->GetContentsView());
- SetInitialBoundsForFramelessWindow(bounds);
+ if (params.parent_widget != gfx::kNullAcceleratedWidget) {
+ // Set the bounds directly instead of applying an inset.
+ SetBounds(bounds);
+ } else {
+ SetInitialBoundsForFramelessWindow(bounds);
+ }
}
observer_manager_.Add(GetNativeTheme());
@@ -1154,10 +1160,16 @@ void Widget::OnNativeWidgetDestroyed() {
}
gfx::Size Widget::GetMinimumSize() const {
+ gfx::Size size;
+ if (widget_delegate_->MaybeGetMinimumSize(&size))
+ return size;
return non_client_view_ ? non_client_view_->GetMinimumSize() : gfx::Size();
}
gfx::Size Widget::GetMaximumSize() const {
+ gfx::Size size;
+ if (widget_delegate_->MaybeGetMaximumSize(&size))
+ return size;
return non_client_view_ ? non_client_view_->GetMaximumSize() : gfx::Size();
}
diff --git ui/views/widget/widget.h ui/views/widget/widget.h
index 0cbc349dd3d1..3dd288962851 100644
--- ui/views/widget/widget.h
+++ ui/views/widget/widget.h
@@ -311,6 +311,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// the concept with bubble anchoring a la BubbleDialogDelegateView.
gfx::NativeView parent = nullptr;
+ gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget;
+
// Specifies the initial bounds of the Widget. Default is empty, which means
// the NativeWidget may specify a default size. If the parent is specified,
// |bounds| is in the parent's coordinate system. If the parent is not
diff --git ui/views/widget/widget_delegate.h ui/views/widget/widget_delegate.h
index 6b4ef19ee72e..08fd84fe2e6e 100644
--- ui/views/widget/widget_delegate.h
+++ ui/views/widget/widget_delegate.h
@@ -305,6 +305,10 @@ class VIEWS_EXPORT WidgetDelegate {
// Returns true if the title text should be centered.
bool ShouldCenterWindowTitleText() const;
+ // CEF supports override of min/max size values.
+ virtual bool MaybeGetMinimumSize(gfx::Size* size) const { return false; }
+ virtual bool MaybeGetMaximumSize(gfx::Size* size) const { return false; }
+
bool focus_traverses_out() const { return params_.focus_traverses_out; }
private:
diff --git ui/views/widget/widget_hwnd_utils.cc ui/views/widget/widget_hwnd_utils.cc
index 89f5b62f95df..8f6971929a12 100644
--- ui/views/widget/widget_hwnd_utils.cc
+++ ui/views/widget/widget_hwnd_utils.cc
@@ -67,7 +67,7 @@ void CalculateWindowStylesFromInitParams(
if (!widget_delegate->CanResize())
*style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
if (params.remove_standard_frame)
- *style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
+ *style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | WS_SYSMENU);
if (native_widget_delegate->IsDialogBox()) {
*style |= DS_MODALFRAME;
diff --git ui/views/win/hwnd_message_handler.cc ui/views/win/hwnd_message_handler.cc
index db4fe784c7e1..a7af3bbb4e0a 100644
--- ui/views/win/hwnd_message_handler.cc
+++ ui/views/win/hwnd_message_handler.cc
@@ -3072,10 +3072,13 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
} else if (event.type() == ui::ET_MOUSEWHEEL) {
ui::MouseWheelEvent mouse_wheel_event(msg);
// Reroute the mouse wheel to the window under the pointer if applicable.
- return (ui::RerouteMouseWheel(hwnd(), w_param, l_param) ||
- delegate_->HandleMouseEvent(&mouse_wheel_event))
- ? 0
- : 1;
+ if (ui::RerouteMouseWheel(hwnd(), w_param, l_param) ||
+ delegate_->HandleMouseEvent(&mouse_wheel_event)) {
+ SetMsgHandled(TRUE);
+ return 0;
+ } else {
+ return 1;
+ }
}
// Suppress |ET_MOUSE_MOVED| and |ET_MOUSE_DRAGGED| events from WM_MOUSE*