summaryrefslogtreecommitdiff
path: root/chromium/ui/views/widget
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/views/widget')
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc10
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h3
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc10
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h8
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc12
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.h10
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc5
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_window_tree_host.h4
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc54
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h9
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc31
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h5
-rw-r--r--chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc15
-rw-r--r--chromium/ui/views/widget/desktop_aura/x11_topmost_window_finder_interactive_uitest.cc23
-rw-r--r--chromium/ui/views/widget/native_widget_aura.cc19
-rw-r--r--chromium/ui/views/widget/native_widget_aura.h2
-rw-r--r--chromium/ui/views/widget/native_widget_mac.h2
-rw-r--r--chromium/ui/views/widget/native_widget_mac.mm34
-rw-r--r--chromium/ui/views/widget/native_widget_mac_accessibility_unittest.mm296
-rw-r--r--chromium/ui/views/widget/native_widget_mac_interactive_uitest.mm52
-rw-r--r--chromium/ui/views/widget/native_widget_mac_unittest.mm95
-rw-r--r--chromium/ui/views/widget/native_widget_private.h2
-rw-r--r--chromium/ui/views/widget/root_view.cc13
-rw-r--r--chromium/ui/views/widget/root_view.h6
-rw-r--r--chromium/ui/views/widget/widget.cc6
-rw-r--r--chromium/ui/views/widget/widget.h11
-rw-r--r--chromium/ui/views/widget/widget_interactive_uitest.cc2
-rw-r--r--chromium/ui/views/widget/widget_unittest.cc5
28 files changed, 498 insertions, 246 deletions
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc
index d53d9c72cc6..5df66d73019 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc
@@ -836,6 +836,16 @@ bool DesktopDragDropClientAuraX11::IsDragDropInProgress() {
return !!g_current_drag_drop_client;
}
+void DesktopDragDropClientAuraX11::AddObserver(
+ aura::client::DragDropClientObserver* observer) {
+ NOTIMPLEMENTED();
+}
+
+void DesktopDragDropClientAuraX11::RemoveObserver(
+ aura::client::DragDropClientObserver* observer) {
+ NOTIMPLEMENTED();
+}
+
void DesktopDragDropClientAuraX11::OnWindowDestroyed(aura::Window* window) {
DCHECK_EQ(target_window_, window);
target_window_ = NULL;
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h
index b8792c2d855..53a8f237e0f 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h
+++ b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.h
@@ -26,6 +26,7 @@
namespace aura {
namespace client {
+class DragDropClientObserver;
class DragDropDelegate;
}
}
@@ -89,6 +90,8 @@ class VIEWS_EXPORT DesktopDragDropClientAuraX11
ui::DragDropTypes::DragEventSource source) override;
void DragCancel() override;
bool IsDragDropInProgress() override;
+ void AddObserver(aura::client::DragDropClientObserver* observer) override;
+ void RemoveObserver(aura::client::DragDropClientObserver* observer) override;
// Overridden from aura::WindowObserver:
void OnWindowDestroyed(aura::Window* window) override;
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc
index 67fd2faa13f..1267b568a30 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.cc
@@ -84,6 +84,16 @@ bool DesktopDragDropClientWin::IsDragDropInProgress() {
return drag_drop_in_progress_;
}
+void DesktopDragDropClientWin::AddObserver(
+ aura::client::DragDropClientObserver* observer) {
+ NOTIMPLEMENTED();
+}
+
+void DesktopDragDropClientWin::RemoveObserver(
+ aura::client::DragDropClientObserver* observer) {
+ NOTIMPLEMENTED();
+}
+
void DesktopDragDropClientWin::OnNativeWidgetDestroying(HWND window) {
if (drop_target_.get()) {
RevokeDragDrop(window);
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h
index 44c28416eea..25845e08f22 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h
+++ b/chromium/ui/views/widget/desktop_aura/desktop_drag_drop_client_win.h
@@ -14,6 +14,12 @@
#include "ui/aura/client/drag_drop_client.h"
#include "ui/views/views_export.h"
+namespace aura {
+namespace client {
+class DragDropClientObserver;
+}
+} // namespace aura
+
namespace ui {
class DragSourceWin;
}
@@ -36,6 +42,8 @@ class VIEWS_EXPORT DesktopDragDropClientWin
ui::DragDropTypes::DragEventSource source) override;
void DragCancel() override;
bool IsDragDropInProgress() override;
+ void AddObserver(aura::client::DragDropClientObserver* observer) override;
+ void RemoveObserver(aura::client::DragDropClientObserver* observer) override;
void OnNativeWidgetDestroying(HWND window);
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc b/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
index a9fdec6c525..aed089087f9 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
@@ -710,7 +710,8 @@ void DesktopNativeWidgetAura::StackAtTop() {
desktop_window_tree_host_->StackAtTop();
}
-void DesktopNativeWidgetAura::SetShape(std::unique_ptr<SkRegion> shape) {
+void DesktopNativeWidgetAura::SetShape(
+ std::unique_ptr<Widget::ShapeRects> shape) {
if (content_window_)
desktop_window_tree_host_->SetShape(std::move(shape));
}
@@ -1150,12 +1151,11 @@ int DesktopNativeWidgetAura::OnPerformDrop(const ui::DropTargetEvent& event) {
////////////////////////////////////////////////////////////////////////////////
// DesktopNativeWidgetAura, aura::WindowTreeHostObserver implementation:
-void DesktopNativeWidgetAura::OnHostCloseRequested(
- const aura::WindowTreeHost* host) {
+void DesktopNativeWidgetAura::OnHostCloseRequested(aura::WindowTreeHost* host) {
GetWidget()->Close();
}
-void DesktopNativeWidgetAura::OnHostResized(const aura::WindowTreeHost* host) {
+void DesktopNativeWidgetAura::OnHostResized(aura::WindowTreeHost* host) {
// Don't update the bounds of the child layers when animating closed. If we
// did it would force a paint, which we don't want. We don't want the paint
// as we can't assume any of the children are valid.
@@ -1168,12 +1168,12 @@ void DesktopNativeWidgetAura::OnHostResized(const aura::WindowTreeHost* host) {
}
void DesktopNativeWidgetAura::OnHostWorkspaceChanged(
- const aura::WindowTreeHost* host) {
+ aura::WindowTreeHost* host) {
native_widget_delegate_->OnNativeWidgetWorkspaceChanged();
}
void DesktopNativeWidgetAura::OnHostMovedInPixels(
- const aura::WindowTreeHost* host,
+ aura::WindowTreeHost* host,
const gfx::Point& new_origin_in_pixels) {
TRACE_EVENT1("views", "DesktopNativeWidgetAura::OnHostMovedInPixels",
"new_origin_in_pixels", new_origin_in_pixels.ToString());
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.h b/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.h
index 01faa59fc6b..cdb96b1b2d3 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.h
+++ b/chromium/ui/views/widget/desktop_aura/desktop_native_widget_aura.h
@@ -138,7 +138,7 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
void SetSize(const gfx::Size& size) override;
void StackAbove(gfx::NativeView native_view) override;
void StackAtTop() override;
- void SetShape(std::unique_ptr<SkRegion> shape) override;
+ void SetShape(std::unique_ptr<Widget::ShapeRects> shape) override;
void Close() override;
void CloseNow() override;
void Show() override;
@@ -231,10 +231,10 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
int OnPerformDrop(const ui::DropTargetEvent& event) override;
// Overridden from aura::WindowTreeHostObserver:
- void OnHostCloseRequested(const aura::WindowTreeHost* host) override;
- void OnHostResized(const aura::WindowTreeHost* host) override;
- void OnHostWorkspaceChanged(const aura::WindowTreeHost* host) override;
- void OnHostMovedInPixels(const aura::WindowTreeHost* host,
+ void OnHostCloseRequested(aura::WindowTreeHost* host) override;
+ void OnHostResized(aura::WindowTreeHost* host) override;
+ void OnHostWorkspaceChanged(aura::WindowTreeHost* host) override;
+ void OnHostMovedInPixels(aura::WindowTreeHost* host,
const gfx::Point& new_origin_in_pixels) override;
private:
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc b/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc
index c31728ca1b4..df8884e7de4 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_screen_x11.cc
@@ -377,8 +377,9 @@ std::vector<display::Display> DesktopScreenX11::BuildDisplaysFromXRandRInfo() {
// TODO(ccameron): Populate this based on this specific display.
// http://crbug.com/735613
if (!display::Display::HasForceColorProfile()) {
- display.set_color_space(
- gfx::ICCProfile::FromBestMonitor().GetColorSpace());
+ gfx::ICCProfile icc_profile = gfx::ICCProfile::FromBestMonitor();
+ icc_profile.HistogramDisplay(display.id());
+ display.set_color_space(icc_profile.GetColorSpace());
}
displays.push_back(display);
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host.h b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host.h
index c8633b68fad..a1cf57dc46e 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host.h
+++ b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host.h
@@ -94,9 +94,9 @@ class VIEWS_EXPORT DesktopWindowTreeHost {
virtual gfx::Rect GetWorkAreaBoundsInScreen() const = 0;
- // Sets the shape of the root window. If |native_region| is NULL then the
+ // Sets the shape of the root window. If |native_shape| is nullptr then the
// window reverts to rectangular.
- virtual void SetShape(std::unique_ptr<SkRegion> native_region) = 0;
+ virtual void SetShape(std::unique_ptr<Widget::ShapeRects> native_shape) = 0;
virtual void Activate() = 0;
virtual void Deactivate() = 0;
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
index 4d0dfbe80e5..e5b007cd0a4 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
@@ -15,7 +15,6 @@
#include "ui/base/cursor/cursor_loader_win.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/win/shell.h"
-#include "ui/compositor/compositor_constants.h"
#include "ui/compositor/paint_context.h"
#include "ui/display/win/dpi.h"
#include "ui/display/win/screen_win.h"
@@ -133,12 +132,7 @@ void DesktopWindowTreeHostWin::Init(aura::Window* content_window,
gfx::Rect pixel_bounds =
display::win::ScreenWin::DIPToScreenRect(nullptr, params.bounds);
message_handler_->Init(parent_hwnd, pixel_bounds);
- if (params.force_software_compositing) {
- ::SetProp(GetAcceleratedWidget(),
- kForceSoftwareCompositor,
- reinterpret_cast<HANDLE>(true));
- }
- CreateCompositor();
+ CreateCompositor(viz::FrameSinkId(), params.force_software_compositing);
OnAcceleratedWidgetAvailable();
InitHost();
window()->Show();
@@ -298,34 +292,34 @@ gfx::Rect DesktopWindowTreeHostWin::GetWorkAreaBoundsInScreen() const {
}
void DesktopWindowTreeHostWin::SetShape(
- std::unique_ptr<SkRegion> native_region) {
- if (!native_region) {
+ std::unique_ptr<Widget::ShapeRects> native_shape) {
+ if (!native_shape || native_shape->empty()) {
message_handler_->SetRegion(nullptr);
return;
}
// TODO(wez): This would be a lot simpler if we were passed an SkPath.
// See crbug.com/410593.
- SkRegion* shape = native_region.get();
- SkRegion device_region;
+ SkRegion shape;
const float scale = display::win::ScreenWin::GetScaleFactorForHWND(GetHWND());
if (scale > 1.0) {
- shape = &device_region;
- std::vector<SkIRect> rects;
- for (SkRegion::Iterator it(*native_region); !it.done(); it.next()) {
- const SkIRect& rect = it.rect();
+ std::vector<SkIRect> sk_rects;
+ for (const gfx::Rect& rect : *native_shape) {
+ const SkIRect sk_rect = gfx::RectToSkIRect(rect);
SkRect scaled_rect =
- SkRect::MakeLTRB(rect.left() * scale, rect.top() * scale,
- rect.right() * scale, rect.bottom() * scale);
+ SkRect::MakeLTRB(sk_rect.left() * scale, sk_rect.top() * scale,
+ sk_rect.right() * scale, sk_rect.bottom() * scale);
SkIRect rounded_scaled_rect;
scaled_rect.roundOut(&rounded_scaled_rect);
- rects.push_back(rounded_scaled_rect);
+ sk_rects.push_back(rounded_scaled_rect);
}
- if (!rects.empty())
- device_region.setRects(&rects[0], rects.size());
+ shape.setRects(&sk_rects[0], sk_rects.size());
+ } else {
+ for (const gfx::Rect& rect : *native_shape)
+ shape.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op);
}
- message_handler_->SetRegion(gfx::CreateHRGNFromSkRegion(*shape));
+ message_handler_->SetRegion(gfx::CreateHRGNFromSkRegion(shape));
}
void DesktopWindowTreeHostWin::Activate() {
@@ -802,11 +796,13 @@ void DesktopWindowTreeHostWin::HandleEndWMSizeMove() {
}
void DesktopWindowTreeHostWin::HandleMove() {
+ CheckForMonitorChange();
native_widget_delegate_->OnNativeWidgetMove();
OnHostMovedInPixels(GetBoundsInPixels().origin());
}
void DesktopWindowTreeHostWin::HandleWorkAreaChanged() {
+ CheckForMonitorChange();
GetWidget()->widget_delegate()->OnWorkAreaChanged();
}
@@ -820,11 +816,13 @@ void DesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
void DesktopWindowTreeHostWin::HandleClientSizeChanged(
const gfx::Size& new_size) {
+ CheckForMonitorChange();
if (dispatcher())
OnHostResizedInPixels(new_size);
}
void DesktopWindowTreeHostWin::HandleFrameChanged() {
+ CheckForMonitorChange();
SetWindowTransparency();
// Replace the frame and layout the contents.
GetWidget()->non_client_view()->UpdateFrame();
@@ -843,6 +841,11 @@ bool DesktopWindowTreeHostWin::HandleMouseEvent(const ui::MouseEvent& event) {
return event.handled();
}
+bool DesktopWindowTreeHostWin::HandlePointerEvent(ui::PointerEvent* event) {
+ SendEventToSink(event);
+ return event->handled();
+}
+
void DesktopWindowTreeHostWin::HandleKeyEvent(ui::KeyEvent* event) {
SendEventToSink(event);
}
@@ -997,6 +1000,15 @@ bool DesktopWindowTreeHostWin::IsModalWindowActive() const {
return false;
}
+void DesktopWindowTreeHostWin::CheckForMonitorChange() {
+ HMONITOR monitor_from_window =
+ ::MonitorFromWindow(GetHWND(), MONITOR_DEFAULTTOPRIMARY);
+ if (monitor_from_window == last_monitor_from_window_)
+ return;
+ last_monitor_from_window_ = monitor_from_window;
+ OnHostDisplayChanged();
+}
+
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHost, public:
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
index 3f1c7bffb61..eb1205ee6a5 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
+++ b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
@@ -77,7 +77,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
gfx::Rect GetRestoredBounds() const override;
std::string GetWorkspace() const override;
gfx::Rect GetWorkAreaBoundsInScreen() const override;
- void SetShape(std::unique_ptr<SkRegion> native_region) override;
+ void SetShape(std::unique_ptr<Widget::ShapeRects> native_shape) override;
void Activate() override;
void Deactivate() override;
bool IsActive() const override;
@@ -188,6 +188,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
void HandleNativeFocus(HWND last_focused_window) override;
void HandleNativeBlur(HWND focused_window) override;
bool HandleMouseEvent(const ui::MouseEvent& event) override;
+ bool HandlePointerEvent(ui::PointerEvent* event) override;
void HandleKeyEvent(ui::KeyEvent* event) override;
void HandleTouchEvent(const ui::TouchEvent& event) override;
bool HandleIMEMessage(UINT message,
@@ -221,6 +222,12 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin
// Returns true if a modal window is active in the current root window chain.
bool IsModalWindowActive() const;
+ // Called whenever the HWND resizes or moves, to see if the nearest HMONITOR
+ // has changed, and, if so, inform the aura::WindowTreeHost.
+ void CheckForMonitorChange();
+
+ HMONITOR last_monitor_from_window_ = nullptr;
+
std::unique_ptr<HWNDMessageHandler> message_handler_;
std::unique_ptr<aura::client::FocusClient> focus_client_;
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
index e8a7a79c534..316cf855f7c 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc
@@ -166,8 +166,7 @@ DesktopWindowTreeHostX11::DesktopWindowTreeHostX11(
has_pointer_focus_(false),
modal_dialog_counter_(0),
close_widget_factory_(this),
- weak_factory_(this) {
-}
+ weak_factory_(this) {}
DesktopWindowTreeHostX11::~DesktopWindowTreeHostX11() {
window()->ClearProperty(kHostForRootWindow);
@@ -701,15 +700,18 @@ gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const {
}
void DesktopWindowTreeHostX11::SetShape(
- std::unique_ptr<SkRegion> native_region) {
+ std::unique_ptr<Widget::ShapeRects> native_shape) {
custom_window_shape_ = false;
window_shape_.reset();
- if (native_region) {
+ if (native_shape) {
+ SkRegion native_region;
+ for (const gfx::Rect& rect : *native_shape)
+ native_region.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op);
gfx::Transform transform = GetRootTransform();
- if (!transform.IsIdentity() && !native_region->isEmpty()) {
+ if (!transform.IsIdentity() && !native_region.isEmpty()) {
SkPath path_in_dip;
- if (native_region->getBoundaryPath(&path_in_dip)) {
+ if (native_region.getBoundaryPath(&path_in_dip)) {
SkPath path_in_pixels;
path_in_dip.transform(transform.matrix(), &path_in_pixels);
window_shape_.reset(gfx::CreateRegionFromSkPath(path_in_pixels));
@@ -717,7 +719,7 @@ void DesktopWindowTreeHostX11::SetShape(
window_shape_.reset(XCreateRegion());
}
} else {
- window_shape_.reset(gfx::CreateRegionFromSkRegion(*native_region));
+ window_shape_.reset(gfx::CreateRegionFromSkRegion(native_region));
}
custom_window_shape_ = true;
@@ -1321,6 +1323,8 @@ void DesktopWindowTreeHostX11::OnDisplayMetricsChanged(
}
}
+void DesktopWindowTreeHostX11::OnMaximizedStateChanged() {}
+
////////////////////////////////////////////////////////////////////////////////
// DesktopWindowTreeHostX11, private:
@@ -1530,7 +1534,10 @@ void DesktopWindowTreeHostX11::InitX11Window(
if (window_icon) {
SetWindowIcons(gfx::ImageSkia(), *window_icon);
}
- CreateCompositor();
+ // Disable compositing on tooltips as a workaround for
+ // https://crbug.com/442111.
+ CreateCompositor(viz::FrameSinkId(),
+ params.type == Widget::InitParams::TYPE_TOOLTIP);
OnAcceleratedWidgetAvailable();
}
@@ -1560,11 +1567,15 @@ void DesktopWindowTreeHostX11::OnWMStateUpdated() {
ui::GetAtomArrayProperty(xwindow_, "_NET_WM_STATE", &atom_list);
bool was_minimized = IsMinimized();
+ bool was_maximized = IsMaximized();
window_properties_.clear();
std::copy(atom_list.begin(), atom_list.end(),
inserter(window_properties_, window_properties_.begin()));
+ bool is_minimized = IsMinimized();
+ bool is_maximized = IsMaximized();
+
// Propagate the window minimization information to the content window, so
// the render side can update its visibility properly. OnWMStateUpdated() is
// called by PropertyNofify event from DispatchEvent() when the browser is
@@ -1577,7 +1588,6 @@ void DesktopWindowTreeHostX11::OnWMStateUpdated() {
// don't draw any 'blank' frames that could be noticed in applications such as
// window manager previews, which show content even when a window is
// minimized.
- bool is_minimized = IsMinimized();
if (is_minimized != was_minimized) {
if (is_minimized) {
compositor()->SetVisible(false);
@@ -1611,6 +1621,9 @@ void DesktopWindowTreeHostX11::OnWMStateUpdated() {
is_always_on_top_ = HasWMSpecProperty("_NET_WM_STATE_ABOVE");
+ if (was_maximized != is_maximized)
+ OnMaximizedStateChanged();
+
// Now that we have different window properties, we may need to relayout the
// window. (The windows code doesn't need this because their window change is
// synchronous.)
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h
index cb189675734..b72ec26d3ed 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h
+++ b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h
@@ -113,7 +113,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
gfx::Rect GetRestoredBounds() const override;
std::string GetWorkspace() const override;
gfx::Rect GetWorkAreaBoundsInScreen() const override;
- void SetShape(std::unique_ptr<SkRegion> native_region) override;
+ void SetShape(std::unique_ptr<Widget::ShapeRects> native_shape) override;
void Activate() override;
void Deactivate() override;
bool IsActive() const override;
@@ -173,6 +173,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostX11
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override;
+ // Called after the window is maximized or restored.
+ virtual void OnMaximizedStateChanged();
+
private:
friend class DesktopWindowTreeHostX11HighDPITest;
// Initializes our X11 surface to draw on. This method performs all
diff --git a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc
index 612b41f5939..32bcd039e1c 100644
--- a/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc
+++ b/chromium/ui/views/widget/desktop_aura/desktop_window_tree_host_x11_unittest.cc
@@ -267,17 +267,10 @@ TEST_F(DesktopWindowTreeHostX11Test, Shape) {
}
// 2) Test setting the window shape via Widget::SetShape().
- gfx::Path shape2;
- shape2.moveTo(10, 0);
- shape2.lineTo(10, 10);
- shape2.lineTo(0, 10);
- shape2.lineTo(0, 100);
- shape2.lineTo(100, 100);
- shape2.lineTo(100, 0);
- shape2.close();
-
- auto shape_region = base::MakeUnique<SkRegion>();
- shape_region->setPath(shape2, SkRegion(shape2.getBounds().round()));
+ auto shape_region = base::MakeUnique<Widget::ShapeRects>();
+ shape_region->emplace_back(10, 0, 90, 10);
+ shape_region->emplace_back(0, 10, 10, 90);
+ shape_region->emplace_back(10, 10, 90, 90);
std::unique_ptr<Widget> widget2(CreateWidget(nullptr));
widget2->Show();
diff --git a/chromium/ui/views/widget/desktop_aura/x11_topmost_window_finder_interactive_uitest.cc b/chromium/ui/views/widget/desktop_aura/x11_topmost_window_finder_interactive_uitest.cc
index d94a8789cbf..18fac097875 100644
--- a/chromium/ui/views/widget/desktop_aura/x11_topmost_window_finder_interactive_uitest.cc
+++ b/chromium/ui/views/widget/desktop_aura/x11_topmost_window_finder_interactive_uitest.cc
@@ -20,7 +20,6 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "third_party/skia/include/core/SkRect.h"
-#include "third_party/skia/include/core/SkRegion.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/platform/x11/x11_event_source.h"
@@ -302,10 +301,10 @@ TEST_F(X11TopmostWindowFinderTest, NonRectangular) {
std::unique_ptr<Widget> widget1(
CreateAndShowWidget(gfx::Rect(100, 100, 100, 100)));
XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
- auto skregion1 = base::MakeUnique<SkRegion>();
- skregion1->op(SkIRect::MakeXYWH(0, 10, 10, 90), SkRegion::kUnion_Op);
- skregion1->op(SkIRect::MakeXYWH(10, 0, 90, 100), SkRegion::kUnion_Op);
- widget1->SetShape(std::move(skregion1));
+ auto shape1 = base::MakeUnique<Widget::ShapeRects>();
+ shape1->emplace_back(0, 10, 10, 90);
+ shape1->emplace_back(10, 0, 90, 100);
+ widget1->SetShape(std::move(shape1));
SkRegion skregion2;
skregion2.op(SkIRect::MakeXYWH(0, 10, 10, 90), SkRegion::kUnion_Op);
@@ -341,10 +340,10 @@ TEST_F(X11TopmostWindowFinderTest, NonRectangularEmptyShape) {
std::unique_ptr<Widget> widget1(
CreateAndShowWidget(gfx::Rect(100, 100, 100, 100)));
XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
- auto skregion1 = base::MakeUnique<SkRegion>();
- skregion1->op(SkIRect::MakeXYWH(0, 0, 0, 0), SkRegion::kUnion_Op);
- // Widget takes ownership of |skregion1|.
- widget1->SetShape(std::move(skregion1));
+ auto shape1 = base::MakeUnique<Widget::ShapeRects>();
+ shape1->emplace_back();
+ // Widget takes ownership of |shape1|.
+ widget1->SetShape(std::move(shape1));
XID xids[] = { xid1 };
StackingClientListWaiter stack_waiter(xids, arraysize(xids));
@@ -362,9 +361,9 @@ TEST_F(X11TopmostWindowFinderTest, NonRectangularNullShape) {
std::unique_ptr<Widget> widget1(
CreateAndShowWidget(gfx::Rect(100, 100, 100, 100)));
XID xid1 = widget1->GetNativeWindow()->GetHost()->GetAcceleratedWidget();
- auto skregion1 = base::MakeUnique<SkRegion>();
- skregion1->op(SkIRect::MakeXYWH(0, 0, 0, 0), SkRegion::kUnion_Op);
- widget1->SetShape(std::move(skregion1));
+ auto shape1 = base::MakeUnique<Widget::ShapeRects>();
+ shape1->emplace_back();
+ widget1->SetShape(std::move(shape1));
// Remove the shape - this is now just a normal window.
widget1->SetShape(nullptr);
diff --git a/chromium/ui/views/widget/native_widget_aura.cc b/chromium/ui/views/widget/native_widget_aura.cc
index 90cd8ab604d..af6022f14ec 100644
--- a/chromium/ui/views/widget/native_widget_aura.cc
+++ b/chromium/ui/views/widget/native_widget_aura.cc
@@ -13,7 +13,7 @@
#include "build/build_config.h"
#include "services/ui/public/interfaces/window_manager.mojom.h"
#include "services/ui/public/interfaces/window_manager_constants.mojom.h"
-#include "third_party/skia/include/core/SkRegion.h"
+#include "services/ui/public/interfaces/window_tree_constants.mojom.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/cursor_client.h"
@@ -62,7 +62,7 @@
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
#endif
-#if defined(USE_X11) && !defined(OS_CHROMEOS)
+#if defined(USE_X11)
#include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#endif
@@ -226,7 +226,10 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
SetRestoreBounds(window_, window_bounds);
else
SetBounds(window_bounds);
- window_->set_ignore_events(!params.accept_events);
+ window_->SetEventTargetingPolicy(
+ params.accept_events
+ ? ui::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS
+ : ui::mojom::EventTargetingPolicy::NONE);
DCHECK(GetWidget()->GetRootView());
if (params.type != Widget::InitParams::TYPE_TOOLTIP)
tooltip_manager_.reset(new views::TooltipManagerAura(GetWidget()));
@@ -490,9 +493,9 @@ void NativeWidgetAura::StackAtTop() {
window_->parent()->StackChildAtTop(window_);
}
-void NativeWidgetAura::SetShape(std::unique_ptr<SkRegion> region) {
+void NativeWidgetAura::SetShape(std::unique_ptr<Widget::ShapeRects> shape) {
if (window_)
- window_->layer()->SetAlphaShape(std::move(region));
+ window_->layer()->SetAlphaShape(std::move(shape));
}
void NativeWidgetAura::Close() {
@@ -1000,7 +1003,7 @@ void NativeWidgetAura::SetInitialFocus(ui::WindowShowState show_state) {
// Widget, public:
namespace {
-#if defined(OS_WIN) || (defined(USE_X11) && !defined(OS_CHROMEOS))
+#if defined(OS_WIN) || defined(USE_X11)
void CloseWindow(aura::Window* window) {
if (window) {
Widget* widget = Widget::GetWidgetForNativeView(window);
@@ -1030,7 +1033,7 @@ void Widget::CloseAllSecondaryWidgets() {
EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0);
#endif
-#if defined(USE_X11) && !defined(OS_CHROMEOS)
+#if defined(USE_X11)
DesktopWindowTreeHostX11::CleanUpWindowList(CloseWindow);
#endif
}
@@ -1042,7 +1045,7 @@ bool Widget::ConvertRect(const Widget* source,
}
const ui::NativeTheme* Widget::GetNativeTheme() const {
-#if defined(USE_X11) && !defined(OS_CHROMEOS)
+#if defined(USE_X11)
const LinuxUI* linux_ui = LinuxUI::instance();
if (linux_ui) {
ui::NativeTheme* native_theme =
diff --git a/chromium/ui/views/widget/native_widget_aura.h b/chromium/ui/views/widget/native_widget_aura.h
index f556bcc14d1..87fc9372272 100644
--- a/chromium/ui/views/widget/native_widget_aura.h
+++ b/chromium/ui/views/widget/native_widget_aura.h
@@ -99,7 +99,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
void SetSize(const gfx::Size& size) override;
void StackAbove(gfx::NativeView native_view) override;
void StackAtTop() override;
- void SetShape(std::unique_ptr<SkRegion> shape) override;
+ void SetShape(std::unique_ptr<Widget::ShapeRects> shape) override;
void Close() override;
void CloseNow() override;
void Show() override;
diff --git a/chromium/ui/views/widget/native_widget_mac.h b/chromium/ui/views/widget/native_widget_mac.h
index 25e52d78ab3..74e3f333e57 100644
--- a/chromium/ui/views/widget/native_widget_mac.h
+++ b/chromium/ui/views/widget/native_widget_mac.h
@@ -84,7 +84,7 @@ class VIEWS_EXPORT NativeWidgetMac : public internal::NativeWidgetPrivate {
void SetSize(const gfx::Size& size) override;
void StackAbove(gfx::NativeView native_view) override;
void StackAtTop() override;
- void SetShape(std::unique_ptr<SkRegion> shape) override;
+ void SetShape(std::unique_ptr<Widget::ShapeRects> shape) override;
void Close() override;
void CloseNow() override;
void Show() override;
diff --git a/chromium/ui/views/widget/native_widget_mac.mm b/chromium/ui/views/widget/native_widget_mac.mm
index 398ea45f1f2..284c7fb7e1e 100644
--- a/chromium/ui/views/widget/native_widget_mac.mm
+++ b/chromium/ui/views/widget/native_widget_mac.mm
@@ -268,7 +268,7 @@ void NativeWidgetMac::GetWindowPlacement(
bool NativeWidgetMac::SetWindowTitle(const base::string16& title) {
NSWindow* window = GetNativeWindow();
NSString* current_title = [window title];
- NSString* new_title = SysUTF16ToNSString(title);
+ NSString* new_title = base::SysUTF16ToNSString(title);
if ([current_title isEqualToString:new_title])
return false;
@@ -333,7 +333,7 @@ void NativeWidgetMac::StackAtTop() {
NOTIMPLEMENTED();
}
-void NativeWidgetMac::SetShape(std::unique_ptr<SkRegion> shape) {
+void NativeWidgetMac::SetShape(std::unique_ptr<Widget::ShapeRects> shape) {
NOTIMPLEMENTED();
}
@@ -742,14 +742,34 @@ void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view,
// static
void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
gfx::NativeView new_parent) {
+ DCHECK_NE(native_view, new_parent);
+ if (!new_parent || [native_view superview] == new_parent) {
+ NOTREACHED();
+ return;
+ }
+
BridgedNativeWidget* bridge =
NativeWidgetMac::GetBridgeForNativeWindow([native_view window]);
- if (bridge && bridge->parent() &&
- bridge->parent()->GetNSWindow() == [new_parent window])
- return; // Nothing to do.
+ BridgedNativeWidget* parent_bridge =
+ NativeWidgetMac::GetBridgeForNativeWindow([new_parent window]);
+ DCHECK(bridge);
+ if (Widget::GetWidgetForNativeView(native_view)->is_top_level() &&
+ bridge->parent() == parent_bridge)
+ return;
+
+ Widget::Widgets widgets;
+ GetAllChildWidgets(native_view, &widgets);
+
+ // First notify all the widgets that they are being disassociated
+ // from their previous parent.
+ for (auto* child : widgets)
+ child->NotifyNativeViewHierarchyWillChange();
+
+ bridge->ReparentNativeView(native_view, new_parent);
- // Not supported. See http://crbug.com/514920.
- NOTREACHED();
+ // And now, notify them that they have a brand new parent.
+ for (auto* child : widgets)
+ child->NotifyNativeViewHierarchyChanged();
}
// static
diff --git a/chromium/ui/views/widget/native_widget_mac_accessibility_unittest.mm b/chromium/ui/views/widget/native_widget_mac_accessibility_unittest.mm
index 357897b4fc7..a9debe71bcc 100644
--- a/chromium/ui/views/widget/native_widget_mac_accessibility_unittest.mm
+++ b/chromium/ui/views/widget/native_widget_mac_accessibility_unittest.mm
@@ -24,19 +24,6 @@
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"
-// Expose some methods from AXPlatformNodeCocoa for testing purposes only.
-@interface AXPlatformNodeCocoa (Testing)
-- (NSString*)AXRole;
-- (id)AXValue;
-
-// Text attributes.
-- (NSString*)AXSelectedText;
-- (NSValue*)AXSelectedTextRange;
-- (NSNumber*)AXNumberOfCharacters;
-- (NSValue*)AXVisibleCharacterRange;
-- (NSNumber*)AXInsertionPointLineNumber;
-@end
-
namespace views {
namespace {
@@ -92,28 +79,44 @@ class TestLabelButton : public LabelButton {
DISALLOW_COPY_AND_ASSIGN(TestLabelButton);
};
+class TestWidgetDelegate : public test::TestDesktopWidgetDelegate {
+ public:
+ TestWidgetDelegate() = default;
+
+ static constexpr char kAccessibleWindowTitle[] = "My Accessible Window";
+
+ // WidgetDelegate:
+ base::string16 GetAccessibleWindowTitle() const override {
+ return base::ASCIIToUTF16(kAccessibleWindowTitle);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
+};
+
+constexpr char TestWidgetDelegate::kAccessibleWindowTitle[];
+
class NativeWidgetMacAccessibilityTest : public test::WidgetTest {
public:
NativeWidgetMacAccessibilityTest() {}
void SetUp() override {
test::WidgetTest::SetUp();
- widget_ = CreateTopLevelPlatformWidget();
- widget_->SetBounds(gfx::Rect(50, 50, 100, 100));
+ widget_delegate_.InitWidget(CreateParams(Widget::InitParams::TYPE_WINDOW));
widget()->Show();
}
void TearDown() override {
- widget_->CloseNow();
+ widget()->CloseNow();
test::WidgetTest::TearDown();
}
id A11yElementAtMidpoint() {
// Accessibility hit tests come in Cocoa screen coordinates.
NSPoint midpoint_in_screen_ = gfx::ScreenPointToNSPoint(
- widget_->GetWindowBoundsInScreen().CenterPoint());
+ widget()->GetWindowBoundsInScreen().CenterPoint());
return
- [widget_->GetNativeWindow() accessibilityHitTest:midpoint_in_screen_];
+ [widget()->GetNativeWindow() accessibilityHitTest:midpoint_in_screen_];
}
id AttributeValueAtMidpoint(NSString* attribute) {
@@ -129,11 +132,71 @@ class NativeWidgetMacAccessibilityTest : public test::WidgetTest {
return textfield;
}
- Widget* widget() { return widget_; }
- gfx::Rect GetWidgetBounds() { return widget_->GetClientAreaBoundsInScreen(); }
+ // Shorthand helpers to get a11y properties from A11yElementAtMidpoint().
+ NSString* AXRole() {
+ return AttributeValueAtMidpoint(NSAccessibilityRoleAttribute);
+ }
+ id AXParent() {
+ return AttributeValueAtMidpoint(NSAccessibilityParentAttribute);
+ }
+ id AXValue() {
+ return AttributeValueAtMidpoint(NSAccessibilityValueAttribute);
+ }
+ NSString* AXTitle() {
+ return AttributeValueAtMidpoint(NSAccessibilityTitleAttribute);
+ }
+ NSString* AXDescription() {
+ return AttributeValueAtMidpoint(NSAccessibilityDescriptionAttribute);
+ }
+ NSString* AXSelectedText() {
+ return AttributeValueAtMidpoint(NSAccessibilitySelectedTextAttribute);
+ }
+ NSValue* AXSelectedTextRange() {
+ return AttributeValueAtMidpoint(NSAccessibilitySelectedTextRangeAttribute);
+ }
+ NSNumber* AXNumberOfCharacters() {
+ return AttributeValueAtMidpoint(NSAccessibilityNumberOfCharactersAttribute);
+ }
+ NSValue* AXVisibleCharacterRange() {
+ return AttributeValueAtMidpoint(
+ NSAccessibilityVisibleCharacterRangeAttribute);
+ }
+ NSNumber* AXInsertionPointLineNumber() {
+ return AttributeValueAtMidpoint(
+ NSAccessibilityInsertionPointLineNumberAttribute);
+ }
+ NSNumber* AXLineForIndex(id parameter) {
+ return [A11yElementAtMidpoint()
+ accessibilityAttributeValue:
+ NSAccessibilityLineForIndexParameterizedAttribute
+ forParameter:parameter];
+ }
+ NSValue* AXRangeForLine(id parameter) {
+ return [A11yElementAtMidpoint()
+ accessibilityAttributeValue:
+ NSAccessibilityRangeForLineParameterizedAttribute
+ forParameter:parameter];
+ }
+ NSString* AXStringForRange(id parameter) {
+ return [A11yElementAtMidpoint()
+ accessibilityAttributeValue:
+ NSAccessibilityStringForRangeParameterizedAttribute
+ forParameter:parameter];
+ }
+ NSAttributedString* AXAttributedStringForRange(id parameter) {
+ return [A11yElementAtMidpoint()
+ accessibilityAttributeValue:
+ NSAccessibilityAttributedStringForRangeParameterizedAttribute
+ forParameter:parameter];
+ }
+
+ Widget* widget() { return widget_delegate_.GetWidget(); }
+ gfx::Rect GetWidgetBounds() {
+ return widget()->GetClientAreaBoundsInScreen();
+ }
private:
- Widget* widget_ = nullptr;
+ TestWidgetDelegate widget_delegate_;
DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacAccessibilityTest);
};
@@ -229,8 +292,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, FocusableElementsAreLeafNodes) {
TestLabelButton* button = new TestLabelButton();
button->SetSize(widget()->GetContentsView()->size());
widget()->GetContentsView()->AddChildView(button);
- EXPECT_NSEQ(NSAccessibilityButtonRole,
- AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
+ EXPECT_NSEQ(NSAccessibilityButtonRole, AXRole());
EXPECT_EQ(
0u,
[[button->GetNativeViewAccessible()
@@ -290,7 +352,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, ParentAttribute) {
// Views with Widget parents will have a NSWindow parent.
EXPECT_NSEQ(
NSAccessibilityWindowRole,
- [AttributeValueAtMidpoint(NSAccessibilityParentAttribute) AXRole]);
+ [AXParent() accessibilityAttributeValue:NSAccessibilityRoleAttribute]);
// Views with non-Widget parents will have the role of the parent view.
widget()->GetContentsView()->RemoveChildView(child);
@@ -299,13 +361,13 @@ TEST_F(NativeWidgetMacAccessibilityTest, ParentAttribute) {
widget()->GetContentsView()->AddChildView(parent);
EXPECT_NSEQ(
NSAccessibilityGroupRole,
- [AttributeValueAtMidpoint(NSAccessibilityParentAttribute) AXRole]);
+ [AXParent() accessibilityAttributeValue:NSAccessibilityRoleAttribute]);
// Test an ignored role parent is skipped in favor of the grandparent.
parent->set_role(ui::AX_ROLE_IGNORED);
EXPECT_NSEQ(
NSAccessibilityWindowRole,
- [AttributeValueAtMidpoint(NSAccessibilityParentAttribute) AXRole]);
+ [AXParent() accessibilityAttributeValue:NSAccessibilityRoleAttribute]);
}
// Test for NSAccessibilityPositionAttribute, including on Widget movement
@@ -337,20 +399,22 @@ TEST_F(NativeWidgetMacAccessibilityTest, HelpAttribute) {
AttributeValueAtMidpoint(NSAccessibilityHelpAttribute));
}
-// Test for NSAccessibilityWindowAttribute and
-// NSAccessibilityTopLevelUIElementAttribute.
-TEST_F(NativeWidgetMacAccessibilityTest, WindowAndTopLevelUIElementAttributes) {
+// Test view properties that should report the native NSWindow, and test
+// specific properties on that NSWindow.
+TEST_F(NativeWidgetMacAccessibilityTest, NativeWindowProperties) {
FlexibleRoleTestView* view = new FlexibleRoleTestView(ui::AX_ROLE_GROUP);
view->SetSize(GetWidgetBounds().size());
widget()->GetContentsView()->AddChildView(view);
// Make sure it's |view| in the hit test by checking its accessibility role.
- EXPECT_EQ(NSAccessibilityGroupRole,
- AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
- EXPECT_NSEQ(widget()->GetNativeWindow(),
- AttributeValueAtMidpoint(NSAccessibilityWindowAttribute));
+ EXPECT_EQ(NSAccessibilityGroupRole, AXRole());
+
+ NSWindow* window = widget()->GetNativeWindow();
+ EXPECT_NSEQ(window, AttributeValueAtMidpoint(NSAccessibilityWindowAttribute));
+ EXPECT_NSEQ(window, AttributeValueAtMidpoint(
+ NSAccessibilityTopLevelUIElementAttribute));
EXPECT_NSEQ(
- widget()->GetNativeWindow(),
- AttributeValueAtMidpoint(NSAccessibilityTopLevelUIElementAttribute));
+ base::SysUTF8ToNSString(TestWidgetDelegate::kAccessibleWindowTitle),
+ [window accessibilityAttributeValue:NSAccessibilityTitleAttribute]);
}
// Tests for accessibility attributes on a views::Textfield.
@@ -375,16 +439,9 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldGenericAttributes) {
boolValue]);
// NSAccessibilityTitleAttribute.
- EXPECT_NSEQ(kTestTitle,
- AttributeValueAtMidpoint(NSAccessibilityTitleAttribute));
-
- // NSAccessibilityValueAttribute.
- EXPECT_NSEQ(kTestStringValue,
- AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
-
- // NSAccessibilityRoleAttribute.
- EXPECT_NSEQ(NSAccessibilityTextFieldRole,
- AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
+ EXPECT_NSEQ(NSAccessibilityTextFieldRole, AXRole());
+ EXPECT_NSEQ(kTestTitle, AXTitle());
+ EXPECT_NSEQ(kTestStringValue, AXValue());
// NSAccessibilitySubroleAttribute and
// NSAccessibilityRoleDescriptionAttribute.
@@ -431,10 +488,8 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldEditableAttributes) {
NSAccessibilityInsertionPointLineNumberAttribute) intValue]);
// NSAccessibilityNumberOfCharactersAttribute.
- EXPECT_EQ(
- kTestStringValue.length,
- [AttributeValueAtMidpoint(NSAccessibilityNumberOfCharactersAttribute)
- unsignedIntegerValue]);
+ EXPECT_EQ(kTestStringValue.length,
+ [AXNumberOfCharacters() unsignedIntegerValue]);
// NSAccessibilityPlaceholderAttribute.
EXPECT_NSEQ(
@@ -443,54 +498,41 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldEditableAttributes) {
// NSAccessibilitySelectedTextAttribute and
// NSAccessibilitySelectedTextRangeAttribute.
- EXPECT_NSEQ(@"",
- AttributeValueAtMidpoint(NSAccessibilitySelectedTextAttribute));
+ EXPECT_NSEQ(@"", AXSelectedText());
// The cursor will be at the end of the textfield, so the selection range will
// span 0 characters and be located at the index after the last character.
EXPECT_EQ(gfx::Range(kTestStringValue.length, kTestStringValue.length),
- gfx::Range([AttributeValueAtMidpoint(
- NSAccessibilitySelectedTextRangeAttribute) rangeValue]));
+ gfx::Range([AXSelectedTextRange() rangeValue]));
// Select some text in the middle of the textfield.
const gfx::Range forward_range(2, 6);
const NSRange ns_range = forward_range.ToNSRange();
textfield->SelectRange(forward_range);
- EXPECT_NSEQ([kTestStringValue substringWithRange:ns_range],
- AttributeValueAtMidpoint(NSAccessibilitySelectedTextAttribute));
+ EXPECT_NSEQ([kTestStringValue substringWithRange:ns_range], AXSelectedText());
EXPECT_EQ(textfield->GetSelectedText(),
- base::SysNSStringToUTF16(AttributeValueAtMidpoint(
- NSAccessibilitySelectedTextAttribute)));
- EXPECT_EQ(forward_range,
- gfx::Range([AttributeValueAtMidpoint(
- NSAccessibilitySelectedTextRangeAttribute) rangeValue]));
+ base::SysNSStringToUTF16(AXSelectedText()));
+ EXPECT_EQ(forward_range, gfx::Range([AXSelectedTextRange() rangeValue]));
const gfx::Range reversed_range(6, 2);
textfield->SelectRange(reversed_range);
// NSRange has no direction, so these are unchanged from the forward range.
- EXPECT_NSEQ([kTestStringValue substringWithRange:ns_range],
- AttributeValueAtMidpoint(NSAccessibilitySelectedTextAttribute));
+ EXPECT_NSEQ([kTestStringValue substringWithRange:ns_range], AXSelectedText());
EXPECT_EQ(textfield->GetSelectedText(),
- base::SysNSStringToUTF16(AttributeValueAtMidpoint(
- NSAccessibilitySelectedTextAttribute)));
- EXPECT_EQ(forward_range,
- gfx::Range([AttributeValueAtMidpoint(
- NSAccessibilitySelectedTextRangeAttribute) rangeValue]));
+ base::SysNSStringToUTF16(AXSelectedText()));
+ EXPECT_EQ(forward_range, gfx::Range([AXSelectedTextRange() rangeValue]));
// NSAccessibilityVisibleCharacterRangeAttribute.
EXPECT_EQ(gfx::Range(0, kTestStringValue.length),
- gfx::Range([AttributeValueAtMidpoint(
- NSAccessibilityVisibleCharacterRangeAttribute) rangeValue]));
+ gfx::Range([AXVisibleCharacterRange() rangeValue]));
// Test an RTL string.
textfield->SetText(base::SysNSStringToUTF16(kTestRTLStringValue));
textfield->SelectRange(forward_range);
EXPECT_EQ(textfield->GetSelectedText(),
- base::SysNSStringToUTF16(AttributeValueAtMidpoint(
- NSAccessibilitySelectedTextAttribute)));
+ base::SysNSStringToUTF16(AXSelectedText()));
textfield->SelectRange(reversed_range);
EXPECT_EQ(textfield->GetSelectedText(),
- base::SysNSStringToUTF16(AttributeValueAtMidpoint(
- NSAccessibilitySelectedTextAttribute)));
+ base::SysNSStringToUTF16(AXSelectedText()));
}
// Test writing accessibility attributes via an accessibility client for normal
@@ -503,8 +545,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, ViewWritableAttributes) {
// Make sure the accessibility object tested is the correct one.
id ax_node = A11yElementAtMidpoint();
EXPECT_TRUE(ax_node);
- EXPECT_NSEQ(NSAccessibilityGroupRole,
- AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
+ EXPECT_NSEQ(NSAccessibilityGroupRole, AXRole());
// Make sure |view| is focusable, then focus/unfocus it.
view->SetFocusBehavior(View::FocusBehavior::ALWAYS);
@@ -530,17 +571,14 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) {
EXPECT_TRUE(ax_node);
// Make sure it's the correct accessibility object.
- id value =
- [ax_node accessibilityAttributeValue:NSAccessibilityValueAttribute];
- EXPECT_NSEQ(kTestStringValue, value);
+ EXPECT_NSEQ(kTestStringValue, AXValue());
// Write a new NSAccessibilityValueAttribute.
EXPECT_TRUE(
[ax_node accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]);
[ax_node accessibilitySetValue:kTestPlaceholderText
forAttribute:NSAccessibilityValueAttribute];
- EXPECT_NSEQ(kTestPlaceholderText,
- AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_NSEQ(kTestPlaceholderText, AXValue());
EXPECT_EQ(base::SysNSStringToUTF16(kTestPlaceholderText), textfield->text());
// Test a read-only textfield.
@@ -549,8 +587,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) {
[ax_node accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]);
[ax_node accessibilitySetValue:kTestStringValue
forAttribute:NSAccessibilityValueAttribute];
- EXPECT_NSEQ(kTestPlaceholderText,
- AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_NSEQ(kTestPlaceholderText, AXValue());
EXPECT_EQ(base::SysNSStringToUTF16(kTestPlaceholderText), textfield->text());
textfield->SetReadOnly(false);
@@ -563,8 +600,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) {
[kTestStringValue stringByAppendingString:kTestPlaceholderText];
[ax_node accessibilitySetValue:kTestStringValue
forAttribute:NSAccessibilitySelectedTextAttribute];
- EXPECT_NSEQ(new_string,
- AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_NSEQ(new_string, AXValue());
EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text());
// Replace entire selection.
@@ -572,8 +608,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) {
textfield->SelectRange(test_range);
[ax_node accessibilitySetValue:kTestStringValue
forAttribute:NSAccessibilitySelectedTextAttribute];
- EXPECT_NSEQ(kTestStringValue,
- AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_NSEQ(kTestStringValue, AXValue());
EXPECT_EQ(base::SysNSStringToUTF16(kTestStringValue), textfield->text());
// Make sure the cursor is at the end of the Textfield.
EXPECT_EQ(gfx::Range([kTestStringValue length]),
@@ -590,8 +625,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextfieldWritableAttributes) {
textfield->SelectRange(test_range);
[ax_node accessibilitySetValue:base::SysUTF16ToNSString(replacement)
forAttribute:NSAccessibilitySelectedTextAttribute];
- EXPECT_NSEQ(new_string,
- AttributeValueAtMidpoint(NSAccessibilityValueAttribute));
+ EXPECT_NSEQ(new_string, AXValue());
EXPECT_EQ(base::SysNSStringToUTF16(new_string), textfield->text());
// Make sure the cursor is at the end of the replacement.
EXPECT_EQ(gfx::Range(front.length() + replacement.length()),
@@ -645,30 +679,17 @@ TEST_F(NativeWidgetMacAccessibilityTest, TextParameterizedAttributes) {
EXPECT_TRUE([ax_node respondsToSelector:sel]);
}
- NSNumber* line =
- [ax_node accessibilityAttributeValue:
- NSAccessibilityLineForIndexParameterizedAttribute
- forParameter:@5];
+ NSNumber* line = AXLineForIndex(@5);
EXPECT_TRUE(line);
EXPECT_EQ(0, [line intValue]);
EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, kTestStringLength)],
- [ax_node accessibilityAttributeValue:
- NSAccessibilityRangeForLineParameterizedAttribute
- forParameter:line]);
+ AXRangeForLine(line));
// The substring "est st" of kTestStringValue.
NSValue* test_range = [NSValue valueWithRange:NSMakeRange(1, 6)];
- EXPECT_NSEQ(@"est st",
- [ax_node accessibilityAttributeValue:
- NSAccessibilityStringForRangeParameterizedAttribute
- forParameter:test_range]);
- EXPECT_NSEQ(
- @"est st",
- [[ax_node
- accessibilityAttributeValue:
- NSAccessibilityAttributedStringForRangeParameterizedAttribute
- forParameter:test_range] string]);
+ EXPECT_NSEQ(@"est st", AXStringForRange(test_range));
+ EXPECT_NSEQ(@"est st", [AXAttributedStringForRange(test_range) string]);
// Not implemented yet. Update these tests when they are.
EXPECT_NSEQ(nil,
@@ -705,8 +726,7 @@ TEST_F(NativeWidgetMacAccessibilityTest, PressAction) {
view->SetSize(GetWidgetBounds().size());
id ax_node = A11yElementAtMidpoint();
- EXPECT_NSEQ(NSAccessibilityButtonRole,
- AttributeValueAtMidpoint(NSAccessibilityRoleAttribute));
+ EXPECT_NSEQ(NSAccessibilityButtonRole, AXRole());
EXPECT_TRUE([[ax_node accessibilityActionNames]
containsObject:NSAccessibilityPressAction]);
@@ -769,35 +789,35 @@ TEST_F(NativeWidgetMacAccessibilityTest, ProtectedTextfields) {
// Explicit checks done without comparing to NSTextField.
EXPECT_TRUE(
[ax_node accessibilityIsAttributeSettable:NSAccessibilityValueAttribute]);
- EXPECT_NSEQ(NSAccessibilityTextFieldRole, [ax_node AXRole]);
+ EXPECT_NSEQ(NSAccessibilityTextFieldRole, AXRole());
NSString* kShownValue = @"•"
@"••••••••••••••••";
// Sanity check.
EXPECT_EQ(kTestStringLength, static_cast<int>([kShownValue length]));
- EXPECT_NSEQ(kShownValue, [ax_node AXValue]);
+ EXPECT_NSEQ(kShownValue, AXValue());
// Cursor currently at the end of input.
- EXPECT_NSEQ(@"", [ax_node AXSelectedText]);
+ EXPECT_NSEQ(@"", AXSelectedText());
EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(kTestStringLength, 0)],
- [ax_node AXSelectedTextRange]);
+ AXSelectedTextRange());
- EXPECT_EQ(kTestStringLength, [[ax_node AXNumberOfCharacters] intValue]);
+ EXPECT_EQ(kTestStringLength, [AXNumberOfCharacters() intValue]);
EXPECT_NSEQ(([NSValue valueWithRange:{0, kTestStringLength}]),
- [ax_node AXVisibleCharacterRange]);
- EXPECT_EQ(0, [[ax_node AXInsertionPointLineNumber] intValue]);
+ AXVisibleCharacterRange());
+ EXPECT_EQ(0, [AXInsertionPointLineNumber() intValue]);
// Test replacing text.
textfield->SetText(base::ASCIIToUTF16("123"));
- EXPECT_NSEQ(@"•••", [ax_node AXValue]);
- EXPECT_EQ(3, [[ax_node AXNumberOfCharacters] intValue]);
+ EXPECT_NSEQ(@"•••", AXValue());
+ EXPECT_EQ(3, [AXNumberOfCharacters() intValue]);
textfield->SelectRange(gfx::Range(2, 3)); // Selects "3".
[ax_node accessibilitySetValue:@"ab"
forAttribute:NSAccessibilitySelectedTextAttribute];
EXPECT_EQ(base::ASCIIToUTF16("12ab"), textfield->text());
- EXPECT_NSEQ(@"••••", [ax_node AXValue]);
- EXPECT_EQ(4, [[ax_node AXNumberOfCharacters] intValue]);
+ EXPECT_NSEQ(@"••••", AXValue());
+ EXPECT_EQ(4, [AXNumberOfCharacters() intValue]);
}
// Test text-specific attributes of Labels.
@@ -811,20 +831,40 @@ TEST_F(NativeWidgetMacAccessibilityTest, Label) {
id ax_node = A11yElementAtMidpoint();
EXPECT_TRUE(ax_node);
- EXPECT_NSEQ(NSAccessibilityStaticTextRole, [ax_node AXRole]);
- EXPECT_NSEQ(kTestStringValue, [ax_node AXValue]);
+ EXPECT_NSEQ(NSAccessibilityStaticTextRole, AXRole());
+ EXPECT_NSEQ(kTestStringValue, AXValue());
+
+ // Title and description for StaticTextRole should always be empty.
+ EXPECT_NSEQ(@"", AXTitle());
+
+ // The description is "The purpose of the element, not including the role.".
+ // BrowserAccessibility returns an empty string instead of nil. Either should
+ // be OK.
+ EXPECT_EQ(nil, AXDescription());
// No selection by default. TODO(tapted): Test selection when views::Label
// uses RenderTextHarfBuzz on Mac. See http://crbug.com/454835.
// For now, this tests that the codepaths are valid for views::Label.
- EXPECT_NSEQ(@"", [ax_node AXSelectedText]);
+ EXPECT_NSEQ(@"", AXSelectedText());
EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, 0)],
- [ax_node AXSelectedTextRange]);
+ AXSelectedTextRange());
- EXPECT_EQ(kTestStringLength, [[ax_node AXNumberOfCharacters] intValue]);
+ EXPECT_EQ(kTestStringLength, [AXNumberOfCharacters() intValue]);
EXPECT_NSEQ(([NSValue valueWithRange:{0, kTestStringLength}]),
- [ax_node AXVisibleCharacterRange]);
- EXPECT_EQ(0, [[ax_node AXInsertionPointLineNumber] intValue]);
+ AXVisibleCharacterRange());
+ EXPECT_EQ(0, [AXInsertionPointLineNumber() intValue]);
+
+ // Test parameterized attributes for Static Text.
+ NSNumber* line = AXLineForIndex(@5);
+ EXPECT_TRUE(line);
+ EXPECT_EQ(0, [line intValue]);
+ EXPECT_NSEQ([NSValue valueWithRange:NSMakeRange(0, kTestStringLength)],
+ AXRangeForLine(line));
+ NSValue* test_range = [NSValue valueWithRange:NSMakeRange(1, 6)];
+ EXPECT_NSEQ(@"est st", AXStringForRange(test_range));
+ EXPECT_NSEQ(@"est st", [AXAttributedStringForRange(test_range) string]);
+
+ // TODO(tapted): Add a test for multiline Labels (currently not supported).
}
class TestComboboxModel : public ui::ComboboxModel {
@@ -851,12 +891,12 @@ TEST_F(NativeWidgetMacAccessibilityTest, Combobox) {
id ax_node = A11yElementAtMidpoint();
EXPECT_TRUE(ax_node);
- EXPECT_NSEQ(NSAccessibilityPopUpButtonRole, [ax_node AXRole]);
+ EXPECT_NSEQ(NSAccessibilityPopUpButtonRole, AXRole());
// The initial value should be the first item in the menu.
- EXPECT_NSEQ(kTestStringValue, [ax_node AXValue]);
+ EXPECT_NSEQ(kTestStringValue, AXValue());
combobox->SetSelectedIndex(1);
- EXPECT_NSEQ(@"Second Item", [ax_node AXValue]);
+ EXPECT_NSEQ(@"Second Item", AXValue());
// Expect to see both a press action and a show menu action. This matches
// Cocoa behavior.
diff --git a/chromium/ui/views/widget/native_widget_mac_interactive_uitest.mm b/chromium/ui/views/widget/native_widget_mac_interactive_uitest.mm
index c29fe0464ff..4e8cf2b6c67 100644
--- a/chromium/ui/views/widget/native_widget_mac_interactive_uitest.mm
+++ b/chromium/ui/views/widget/native_widget_mac_interactive_uitest.mm
@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "ui/base/test/ui_controls.h"
#import "ui/base/test/windowed_nsnotification_observer.h"
+#import "ui/events/test/cocoa_test_event_utils.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
#include "ui/views/test/test_widget_observer.h"
#include "ui/views/test/widget_test.h"
@@ -221,6 +222,57 @@ TEST_F(NativeWidgetMacInteractiveUITest, ParentWindowTrafficLights) {
parent_widget->CloseNow();
}
+// Test that bubble widgets are dismissed on right mouse down.
+TEST_F(NativeWidgetMacInteractiveUITest, BubbleDismiss) {
+ Widget* parent_widget = CreateTopLevelPlatformWidget();
+ parent_widget->SetBounds(gfx::Rect(100, 100, 100, 100));
+ ShowKeyWindow(parent_widget);
+
+ Widget* bubble_widget =
+ BubbleDialogDelegateView::CreateBubble(new TestBubbleView(parent_widget));
+ ShowKeyWindow(bubble_widget);
+
+ // First, test with LeftMouseDown in the parent window.
+ NSEvent* mouse_down = cocoa_test_event_utils::LeftMouseDownAtPointInWindow(
+ NSMakePoint(50, 50), parent_widget->GetNativeWindow());
+ [NSApp sendEvent:mouse_down];
+ EXPECT_TRUE(bubble_widget->IsClosed());
+
+ bubble_widget =
+ BubbleDialogDelegateView::CreateBubble(new TestBubbleView(parent_widget));
+ ShowKeyWindow(bubble_widget);
+
+ // Test with RightMouseDown in the parent window.
+ mouse_down = cocoa_test_event_utils::RightMouseDownAtPointInWindow(
+ NSMakePoint(50, 50), parent_widget->GetNativeWindow());
+ [NSApp sendEvent:mouse_down];
+ EXPECT_TRUE(bubble_widget->IsClosed());
+
+ bubble_widget =
+ BubbleDialogDelegateView::CreateBubble(new TestBubbleView(parent_widget));
+ ShowKeyWindow(bubble_widget);
+
+ // Test with RightMouseDown in the bubble (bubble should stay open).
+ mouse_down = cocoa_test_event_utils::RightMouseDownAtPointInWindow(
+ NSMakePoint(50, 50), bubble_widget->GetNativeWindow());
+ [NSApp sendEvent:mouse_down];
+ EXPECT_FALSE(bubble_widget->IsClosed());
+ bubble_widget->CloseNow();
+
+ // Test with RightMouseDown when set_close_on_deactivate(false).
+ TestBubbleView* bubble_view = new TestBubbleView(parent_widget);
+ bubble_view->set_close_on_deactivate(false);
+ bubble_widget = BubbleDialogDelegateView::CreateBubble(bubble_view);
+ ShowKeyWindow(bubble_widget);
+
+ mouse_down = cocoa_test_event_utils::RightMouseDownAtPointInWindow(
+ NSMakePoint(50, 50), parent_widget->GetNativeWindow());
+ [NSApp sendEvent:mouse_down];
+ EXPECT_FALSE(bubble_widget->IsClosed());
+
+ parent_widget->CloseNow();
+}
+
INSTANTIATE_TEST_CASE_P(NativeWidgetMacInteractiveUITestInstance,
NativeWidgetMacInteractiveUITest,
::testing::Bool());
diff --git a/chromium/ui/views/widget/native_widget_mac_unittest.mm b/chromium/ui/views/widget/native_widget_mac_unittest.mm
index edd51fb6a44..5a2188cb882 100644
--- a/chromium/ui/views/widget/native_widget_mac_unittest.mm
+++ b/chromium/ui/views/widget/native_widget_mac_unittest.mm
@@ -664,7 +664,7 @@ TEST_F(NativeWidgetMacTest, AccessibilityIntegration) {
NSPoint midpoint = NSMakePoint(NSMidX(nsrect), NSMidY(nsrect));
id hit = [widget->GetNativeWindow() accessibilityHitTest:midpoint];
- id title = [hit accessibilityAttributeValue:NSAccessibilityTitleAttribute];
+ id title = [hit accessibilityAttributeValue:NSAccessibilityValueAttribute];
EXPECT_NSEQ(title, @"Green");
widget->CloseNow();
@@ -915,11 +915,17 @@ class ModalDialogDelegate : public DialogDelegateView {
explicit ModalDialogDelegate(ui::ModalType modal_type)
: modal_type_(modal_type) {}
+ void set_can_close(bool value) { can_close_ = value; }
+
// WidgetDelegate:
ui::ModalType GetModalType() const override { return modal_type_; }
+ // DialogDelegate:
+ bool Close() override { return can_close_; }
+
private:
const ui::ModalType modal_type_;
+ bool can_close_ = true;
DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate);
};
@@ -1697,6 +1703,80 @@ TEST_F(NativeWidgetMacTest, ChangeFocusOnChangeFirstResponder) {
widget->CloseNow();
}
+// Ensure reparented native view has correct bounds.
+TEST_F(NativeWidgetMacTest, ReparentNativeViewBounds) {
+ Widget* parent = CreateTopLevelFramelessPlatformWidget();
+ gfx::Rect parent_rect(100, 100, 300, 200);
+ parent->SetBounds(parent_rect);
+
+ Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
+ params.parent = parent->GetNativeView();
+ Widget* widget = new Widget;
+ widget->Init(params);
+ widget->SetContentsView(new View);
+
+ NSView* child_view = widget->GetNativeView();
+ Widget::ReparentNativeView(child_view, parent->GetNativeView());
+
+ // Reparented content view has the size of the Widget that created it.
+ gfx::Rect widget_rect(0, 0, 200, 100);
+ widget->SetBounds(widget_rect);
+ EXPECT_EQ(200, NSWidth([child_view frame]));
+ EXPECT_EQ(100, NSHeight([child_view frame]));
+
+ // Reparented widget has bounds relative to the native parent
+ NSRect native_parent_rect = NSMakeRect(50, 100, 200, 70);
+ base::scoped_nsobject<NSView> native_parent(
+ [[NSView alloc] initWithFrame:native_parent_rect]);
+ [parent->GetNativeView() addSubview:native_parent];
+
+ gfx::Rect screen_rect = widget->GetWindowBoundsInScreen();
+ EXPECT_EQ(100, screen_rect.x());
+ EXPECT_EQ(100, screen_rect.y());
+
+ Widget::ReparentNativeView(child_view, native_parent);
+ widget->SetBounds(widget_rect);
+ screen_rect = widget->GetWindowBoundsInScreen();
+ EXPECT_EQ(150, screen_rect.x());
+ EXPECT_EQ(130, screen_rect.y());
+
+ parent->CloseNow();
+}
+
+// Test two kinds of widgets to re-parent.
+TEST_F(NativeWidgetMacTest, ReparentNativeViewTypes) {
+ std::unique_ptr<Widget> toplevel1(new Widget);
+ Widget::InitParams toplevel_params =
+ CreateParams(Widget::InitParams::TYPE_POPUP);
+ toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
+ toplevel1->Init(toplevel_params);
+
+ std::unique_ptr<Widget> toplevel2(new Widget);
+ toplevel2->Init(toplevel_params);
+
+ Widget* child = new Widget;
+ Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL);
+ child->Init(child_params);
+
+ Widget::ReparentNativeView(child->GetNativeView(),
+ toplevel1->GetNativeView());
+ EXPECT_EQ([child->GetNativeView() window],
+ [toplevel1->GetNativeView() window]);
+ EXPECT_EQ(0, [child->GetNativeWindow() alphaValue]);
+
+ Widget::ReparentNativeView(child->GetNativeView(),
+ toplevel2->GetNativeView());
+ EXPECT_EQ([child->GetNativeView() window],
+ [toplevel2->GetNativeView() window]);
+ EXPECT_EQ(0, [child->GetNativeWindow() alphaValue]);
+ EXPECT_NE(0, [toplevel1->GetNativeWindow() alphaValue]);
+
+ Widget::ReparentNativeView(toplevel2->GetNativeView(),
+ toplevel1->GetNativeView());
+ EXPECT_EQ([toplevel2->GetNativeWindow() parentWindow],
+ [toplevel1->GetNativeView() window]);
+}
+
// Test class for Full Keyboard Access related tests.
class NativeWidgetMacFullKeyboardAccessTest : public NativeWidgetMacTest {
public:
@@ -1877,6 +1957,19 @@ TEST_F(NativeWidgetMacViewsOrderTest, UnassociatedViewsIsAbove) {
]]));
}
+// Test -[NSWindowDelegate windowShouldClose:].
+TEST_F(NativeWidgetMacTest, CanClose) {
+ ModalDialogDelegate* delegate = new ModalDialogDelegate(ui::MODAL_TYPE_NONE);
+ Widget* widget =
+ views::DialogDelegate::CreateDialogWidget(delegate, nullptr, nullptr);
+ NSWindow* window = widget->GetNativeWindow();
+ delegate->set_can_close(false);
+ EXPECT_FALSE([[window delegate] windowShouldClose:window]);
+ delegate->set_can_close(true);
+ EXPECT_TRUE([[window delegate] windowShouldClose:window]);
+ widget->CloseNow();
+}
+
} // namespace test
} // namespace views
diff --git a/chromium/ui/views/widget/native_widget_private.h b/chromium/ui/views/widget/native_widget_private.h
index dfe37828b68..ebeb4e377b9 100644
--- a/chromium/ui/views/widget/native_widget_private.h
+++ b/chromium/ui/views/widget/native_widget_private.h
@@ -176,7 +176,7 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
virtual void SetSize(const gfx::Size& size) = 0;
virtual void StackAbove(gfx::NativeView native_view) = 0;
virtual void StackAtTop() = 0;
- virtual void SetShape(std::unique_ptr<SkRegion> shape) = 0;
+ virtual void SetShape(std::unique_ptr<Widget::ShapeRects> shape) = 0;
virtual void Close() = 0;
virtual void CloseNow() = 0;
virtual void Show() = 0;
diff --git a/chromium/ui/views/widget/root_view.cc b/chromium/ui/views/widget/root_view.cc
index 37e54bdf2d7..acc2aaf61d0 100644
--- a/chromium/ui/views/widget/root_view.cc
+++ b/chromium/ui/views/widget/root_view.cc
@@ -219,10 +219,6 @@ void RootView::ThemeChanged() {
View::PropagateThemeChanged();
}
-void RootView::LocaleChanged() {
- View::PropagateLocaleChanged();
-}
-
void RootView::DeviceScaleFactorChanged(float device_scale_factor) {
View::PropagateDeviceScaleFactorChanged(device_scale_factor);
}
@@ -644,12 +640,13 @@ void RootView::OnPaint(gfx::Canvas* canvas) {
View::OnPaint(canvas);
}
-gfx::Vector2d RootView::CalculateOffsetToAncestorWithLayer(
+View::LayerOffsetData RootView::CalculateOffsetToAncestorWithLayer(
ui::Layer** layer_parent) {
- gfx::Vector2d offset(View::CalculateOffsetToAncestorWithLayer(layer_parent));
- if (!layer() && layer_parent)
+ if (layer() || !widget_->GetLayer())
+ return View::CalculateOffsetToAncestorWithLayer(layer_parent);
+ if (layer_parent)
*layer_parent = widget_->GetLayer();
- return offset;
+ return LayerOffsetData(widget_->GetLayer()->device_scale_factor());
}
View::DragInfo* RootView::GetDragInfo() {
diff --git a/chromium/ui/views/widget/root_view.h b/chromium/ui/views/widget/root_view.h
index d8212a24d78..17ae8112718 100644
--- a/chromium/ui/views/widget/root_view.h
+++ b/chromium/ui/views/widget/root_view.h
@@ -83,10 +83,6 @@ class VIEWS_EXPORT RootView : public View,
// hierarchy.
void ThemeChanged();
- // Public API for broadcasting locale change notifications to this View
- // hierarchy.
- void LocaleChanged();
-
// Public API for broadcasting device scale factor change notifications to
// this View hierarchy.
void DeviceScaleFactorChanged(float device_scale_factor);
@@ -125,7 +121,7 @@ class VIEWS_EXPORT RootView : public View,
const ViewHierarchyChangedDetails& details) override;
void VisibilityChanged(View* starting_from, bool is_visible) override;
void OnPaint(gfx::Canvas* canvas) override;
- gfx::Vector2d CalculateOffsetToAncestorWithLayer(
+ View::LayerOffsetData CalculateOffsetToAncestorWithLayer(
ui::Layer** layer_parent) override;
View::DragInfo* GetDragInfo() override;
diff --git a/chromium/ui/views/widget/widget.cc b/chromium/ui/views/widget/widget.cc
index 32a50e8860a..d37585c6fa3 100644
--- a/chromium/ui/views/widget/widget.cc
+++ b/chromium/ui/views/widget/widget.cc
@@ -567,7 +567,7 @@ void Widget::StackAtTop() {
native_widget_->StackAtTop();
}
-void Widget::SetShape(std::unique_ptr<SkRegion> shape) {
+void Widget::SetShape(std::unique_ptr<ShapeRects> shape) {
native_widget_->SetShape(std::move(shape));
}
@@ -857,10 +857,6 @@ void Widget::ThemeChanged() {
root_view_->ThemeChanged();
}
-void Widget::LocaleChanged() {
- root_view_->LocaleChanged();
-}
-
void Widget::DeviceScaleFactorChanged(float device_scale_factor) {
root_view_->DeviceScaleFactorChanged(device_scale_factor);
}
diff --git a/chromium/ui/views/widget/widget.h b/chromium/ui/views/widget/widget.h
index 63fcb9d611e..6590ea90b80 100644
--- a/chromium/ui/views/widget/widget.h
+++ b/chromium/ui/views/widget/widget.h
@@ -109,7 +109,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
public FocusTraversable,
public ui::NativeThemeObserver {
public:
- typedef std::set<Widget*> Widgets;
+ using Widgets = std::set<Widget*>;
+ using ShapeRects = std::vector<gfx::Rect>;
enum FrameType {
FRAME_TYPE_DEFAULT, // Use whatever the default would be.
@@ -484,7 +485,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// Sets a shape on the widget. Passing a NULL |shape| reverts the widget to
// be rectangular.
- void SetShape(std::unique_ptr<SkRegion> shape);
+ void SetShape(std::unique_ptr<ShapeRects> shape);
// Hides the widget then closes it after a return to the message loop.
virtual void Close();
@@ -641,10 +642,6 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
// changed.
void ThemeChanged();
- // Notifies the view hierarchy contained in this widget that locale resources
- // changed.
- void LocaleChanged();
-
// Notifies the view hierarchy contained in this widget that the device scale
// factor changed.
void DeviceScaleFactorChanged(float device_scale_factor);
@@ -859,7 +856,7 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
private:
friend class ComboboxTest;
- friend class CustomButtonTest;
+ friend class ButtonTest;
friend class TextfieldTest;
friend class ViewAuraTest;
diff --git a/chromium/ui/views/widget/widget_interactive_uitest.cc b/chromium/ui/views/widget/widget_interactive_uitest.cc
index 75aba4f70ef..fd641827713 100644
--- a/chromium/ui/views/widget/widget_interactive_uitest.cc
+++ b/chromium/ui/views/widget/widget_interactive_uitest.cc
@@ -62,7 +62,7 @@ class ExitLoopOnRelease : public View {
// View:
void OnMouseReleased(const ui::MouseEvent& event) override {
GetWidget()->Close();
- base::MessageLoop::current()->QuitNow();
+ base::RunLoop::QuitCurrentDeprecated();
}
DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease);
diff --git a/chromium/ui/views/widget/widget_unittest.cc b/chromium/ui/views/widget/widget_unittest.cc
index e321d91b9a0..9cddacbcda9 100644
--- a/chromium/ui/views/widget/widget_unittest.cc
+++ b/chromium/ui/views/widget/widget_unittest.cc
@@ -8,7 +8,6 @@
#include "base/bind.h"
#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
@@ -1059,7 +1058,7 @@ TEST_F(WidgetTest, GetWindowPlacement) {
#endif
WidgetAutoclosePtr widget;
-#if defined(USE_X11) && !defined(OS_CHROMEOS)
+#if defined(USE_X11)
// On desktop-Linux cheat and use non-desktop widgets. On X11, minimize is
// asynchronous. Also (harder) showing a window doesn't activate it without
// user interaction (or extra steps only done for interactive ui tests).
@@ -2096,7 +2095,7 @@ class CloseDestroysWidget : public Widget {
~CloseDestroysWidget() override {
if (destroyed_) {
*destroyed_ = true;
- base::MessageLoop::current()->QuitNow();
+ base::RunLoop::QuitCurrentDeprecated();
}
}