diff --git content/browser/renderer_host/render_widget_host_view_base.cc content/browser/renderer_host/render_widget_host_view_base.cc index f41270e26278..38303c9c3ec8 100644 --- content/browser/renderer_host/render_widget_host_view_base.cc +++ content/browser/renderer_host/render_widget_host_view_base.cc @@ -577,6 +577,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 8e523d78e765..d951d8915864 100644 --- content/browser/renderer_host/render_widget_host_view_base.h +++ content/browser/renderer_host/render_widget_host_view_base.h @@ -71,6 +71,7 @@ class CursorManager; class MouseWheelPhaseHandler; class RenderWidgetHostImpl; class RenderWidgetHostViewBaseObserver; +class RenderWidgetHostViewGuest; class SyntheticGestureTarget; class TextInputManager; class TouchSelectionControllerClientManager; @@ -91,6 +92,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; @@ -125,6 +129,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 SetRecordTabSwitchTimeRequest(base::TimeTicks start_time, @@ -479,6 +485,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; @@ -643,6 +655,10 @@ class CONTENT_EXPORT RenderWidgetHostViewBase bool is_currently_scrolling_viewport_ = false; + // True if the widget has a external parent view/window outside of the + // Chromium-controlled view/window hierarchy. + bool has_external_parent_; + 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 21f93de01aa5..8b7ec41d94da 100644 --- content/browser/renderer_host/render_widget_host_view_event_handler.cc +++ content/browser/renderer_host/render_widget_host_view_event_handler.cc @@ -32,6 +32,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 "content/public/common/context_menu_params.h" @@ -922,6 +926,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 07d4351d0a8a..4ad78ab76a7c 100644 --- content/public/browser/render_widget_host_view.h +++ content/public/browser/render_widget_host_view.h @@ -246,6 +246,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 7df0a3a8ed26..4078efb5ad10 100644 --- ui/base/x/x11_window.cc +++ ui/base/x/x11_window.cc @@ -190,8 +190,12 @@ void XWindow::Init(const Configuration& config) { attribute_mask |= CWBorderPixel; swa.border_pixel = 0; + gfx::AcceleratedWidget parent_widget = config.parent_widget; + if (parent_widget == gfx::kNullAcceleratedWidget) + parent_widget = x_root_window_; + bounds_in_pixels_ = SanitizeBounds(config.bounds); - xwindow_ = XCreateWindow(xdisplay_, x_root_window_, bounds_in_pixels_.x(), + xwindow_ = XCreateWindow(xdisplay_, parent_widget, bounds_in_pixels_.x(), bounds_in_pixels_.y(), bounds_in_pixels_.width(), bounds_in_pixels_.height(), 0, // border width diff --git ui/base/x/x11_window.h ui/base/x/x11_window.h index 97d8273414fa..b8784d044c61 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/x11.h" #include "ui/gfx/x/x11_types.h" @@ -86,6 +87,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; }; explicit XWindow(Delegate* delegate); diff --git ui/views/widget/desktop_aura/desktop_screen_win.cc ui/views/widget/desktop_aura/desktop_screen_win.cc index 70553b153c44..ecd99bc78373 100644 --- ui/views/widget/desktop_aura/desktop_screen_win.cc +++ ui/views/widget/desktop_aura/desktop_screen_win.cc @@ -30,6 +30,8 @@ display::Display DesktopScreenWin::GetDisplayMatching( } HWND DesktopScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { + if (!window) + return NULL; aura::WindowTreeHost* host = window->GetHost(); return host ? host->GetAcceleratedWidget() : nullptr; } 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 7e31a1c159af..eb0451b8913a 100644 --- ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc +++ ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc @@ -95,6 +95,7 @@ DesktopWindowTreeHostWin::DesktopWindowTreeHostWin( should_animate_window_close_(false), pending_close_(false), has_non_client_view_(false), + has_external_parent_(false), tooltip_(nullptr) {} DesktopWindowTreeHostWin::~DesktopWindowTreeHostWin() { @@ -128,8 +129,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); @@ -891,11 +896,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 335db0db49bb..7f60402ed086 100644 --- ui/views/widget/desktop_aura/desktop_window_tree_host_win.h +++ ui/views/widget/desktop_aura/desktop_window_tree_host_win.h @@ -288,6 +288,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_; + // 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 b03a5bc9d509..bcbf960a130e 100644 --- ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc +++ ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc @@ -139,6 +139,7 @@ ui::XWindow::Configuration ConvertInitParamsToX11WindowConfig( config.wm_class_name = params.wm_class_name; config.wm_class_class = params.wm_class_class; config.wm_role_name = params.wm_role_name; + config.parent_widget = params.parent_widget; return config; } @@ -246,6 +247,8 @@ std::vector DesktopWindowTreeHostX11::GetAllOpenWindows() { } gfx::Rect DesktopWindowTreeHostX11::GetX11RootWindowBounds() const { + if (!screen_bounds_.IsEmpty()) + return screen_bounds_; return x11_window_->bounds(); } @@ -540,6 +543,8 @@ void DesktopWindowTreeHostX11::GetWindowPlacement( } gfx::Rect DesktopWindowTreeHostX11::GetWindowBoundsInScreen() const { + if (!screen_bounds_.IsEmpty()) + return screen_bounds_; gfx::Rect bounds_in_pixels = x11_window_->bounds(); return ToDIPRect(bounds_in_pixels); } @@ -954,6 +959,9 @@ void DesktopWindowTreeHostX11::SetBoundsInPixels( } gfx::Point DesktopWindowTreeHostX11::GetLocationOnScreenInPixels() const { + if (!screen_bounds_.IsEmpty()) + return screen_bounds_.origin(); + return x11_window_->bounds().origin(); } @@ -1280,6 +1288,11 @@ void DesktopWindowTreeHostX11::InitX11Window(const Widget::InitParams& params) { config.background_color = background_color; config.prefer_dark_theme = linux_ui && linux_ui->PreferDarkTheme(); config.icon = ViewsDelegate::GetInstance()->GetDefaultWindowIcon(); + + gfx::AcceleratedWidget parent_widget = config.parent_widget; + if (parent_widget != gfx::kNullAcceleratedWidget) + has_external_parent_ = true; + x11_window_->Init(config); // Disable compositing on tooltips as a workaround for 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 e32726ad4616..cad33f22bf74 100644 --- ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h +++ ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h @@ -102,6 +102,12 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 // be changed after. void SetVisualId(VisualID visual_id); + 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; @@ -294,6 +300,13 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11 // behavior if > 0. ui::ZOrderLevel z_order_ = ui::ZOrderLevel::kNormal; + // 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; std::unique_ptr x11_non_client_event_filter_; diff --git ui/views/widget/widget.cc ui/views/widget/widget.cc index 0cb75272c2ca..ef79679114d4 100644 --- ui/views/widget/widget.cc +++ ui/views/widget/widget.cc @@ -157,6 +157,7 @@ Widget::InitParams::InitParams(Type type) use_system_default_icon(false), show_state(ui::SHOW_STATE_DEFAULT), parent(nullptr), + parent_widget(gfx::kNullAcceleratedWidget), native_widget(nullptr), desktop_window_tree_host(nullptr), layer_type(ui::LAYER_TEXTURED), @@ -325,7 +326,7 @@ void Widget::Init(const InitParams& in_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; if (params.opacity == views::Widget::InitParams::INFER_OPACITY && params.type != views::Widget::InitParams::TYPE_WINDOW) { @@ -389,7 +390,12 @@ void Widget::Init(const InitParams& in_params) { } } else if (params.delegate) { SetContentsView(params.delegate->GetContentsView()); - SetInitialBoundsForFramelessWindow(params.bounds); + if (params.parent_widget) { + // Set the bounds directly instead of applying an inset. + SetBounds(params.bounds); + } else { + SetInitialBoundsForFramelessWindow(params.bounds); + } } // TODO(https://crbug.com/953978): Use GetNativeTheme() for all platforms. #if defined(OS_MACOSX) || defined(OS_WIN) @@ -1175,10 +1181,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 83ba608199b4..546cbe32020c 100644 --- ui/views/widget/widget.h +++ ui/views/widget/widget.h @@ -259,6 +259,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // Whether the widget should be maximized or minimized. ui::WindowShowState show_state; gfx::NativeView parent; + gfx::AcceleratedWidget parent_widget; // 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 77585733e699..77c5db949902 100644 --- ui/views/widget/widget_delegate.h +++ ui/views/widget/widget_delegate.h @@ -191,6 +191,10 @@ class VIEWS_EXPORT WidgetDelegate { // be cycled through with keyboard focus. virtual void GetAccessiblePanes(std::vector* panes) {} + // 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; } + protected: virtual ~WidgetDelegate(); diff --git ui/views/widget/widget_hwnd_utils.cc ui/views/widget/widget_hwnd_utils.cc index 9edfa2c00c4b..8a9217578609 100644 --- ui/views/widget/widget_hwnd_utils.cc +++ ui/views/widget/widget_hwnd_utils.cc @@ -66,7 +66,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 9b683f301913..8609f61ebd0f 100644 --- ui/views/win/hwnd_message_handler.cc +++ ui/views/win/hwnd_message_handler.cc @@ -2963,10 +2963,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; + } } // There are cases where the code handling the message destroys the window,