Skip to content

Commit

Permalink
Reland "wm/views: makes objects using Env take Env"
Browse files Browse the repository at this point in the history
This reverts commit 07aab20.

Reason for revert: msan issue was fixed and landed (and wasn't triggered by this patch). Reverting the revert to reland.

Original change's description:
> Revert "wm/views: makes objects using Env take Env"
> 
> This reverts commit 9feb99a.
> 
> Reason for revert: a patch earlier in the chain caused msan failures.
> 
> Original change's description:
> > wm/views: makes objects using Env take Env
> > 
> > This allows for multiple Envs at the same time. Additionally:
> > . NativeWidgetPrivate::CreateNativeWidget: now takes InitParams
> > . NativeWidgetPrivate::IsMouseButtonDown() is now an member function.
> > 
> > BUG=847992
> > TEST=covered by tests
> > 
> > Change-Id: Ic35b274c0a927a7c602809a7e611383b5d3dd3e2
> > Reviewed-on: https://chromium-review.googlesource.com/1166148
> > Commit-Queue: Scott Violet <sky@chromium.org>
> > Reviewed-by: Michael Wasserman <msw@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#581621}
> 
> TBR=sky@chromium.org,msw@chromium.org
> 
> Change-Id: I9410bf471a71d07b32f49a139b7afa9ced0f3fea
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 847992
> Reviewed-on: https://chromium-review.googlesource.com/1168403
> Reviewed-by: Scott Violet <sky@chromium.org>
> Commit-Queue: Scott Violet <sky@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#581716}

TBR=sky@chromium.org,msw@chromium.org

Change-Id: I1fcd75fb66d00693dfc2e0b78e871848a335319a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 847992
Reviewed-on: https://chromium-review.googlesource.com/1168566
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581797}
  • Loading branch information
Scott Violet authored and Commit Bot committed Aug 9, 2018
1 parent 3652916 commit b283bc8
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 90 deletions.
1 change: 1 addition & 0 deletions ui/aura/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ class AURA_EXPORT Window : public ui::LayerDelegate,
bool IsEmbeddingClient() const;

Env* env() { return env_; }
const Env* env() const { return env_; }

// ui::GestureConsumer:
bool RequiresDoubleTapGestureEvents() const override;
Expand Down
62 changes: 32 additions & 30 deletions ui/views/controls/native/native_view_host_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,24 @@ class NativeViewHostAura::ClippingWindowDelegate : public aura::WindowDelegate {
aura::Window* native_view_;
};

NativeViewHostAura::NativeViewHostAura(NativeViewHost* host)
: host_(host),
clipping_window_delegate_(new ClippingWindowDelegate()),
clipping_window_(clipping_window_delegate_.get()) {
// Set the type so descendant views (including popups) get positioned
// appropriately.
clipping_window_.SetType(aura::client::WINDOW_TYPE_CONTROL);
clipping_window_.Init(ui::LAYER_NOT_DRAWN);
clipping_window_.set_owned_by_parent(false);
clipping_window_.SetName("NativeViewHostAuraClip");
clipping_window_.layer()->SetMasksToBounds(true);
clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_));
}
NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) : host_(host) {}

NativeViewHostAura::~NativeViewHostAura() {
if (host_->native_view()) {
host_->native_view()->RemoveObserver(this);
host_->native_view()->ClearProperty(views::kHostViewKey);
host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
clipping_window_.ClearProperty(views::kHostViewKey);
if (host_->native_view()->parent() == &clipping_window_)
clipping_window_.RemoveChild(host_->native_view());
clipping_window_->ClearProperty(views::kHostViewKey);
if (host_->native_view()->parent() == clipping_window_.get())
clipping_window_->RemoveChild(host_->native_view());
}
}

////////////////////////////////////////////////////////////////////////////////
// NativeViewHostAura, NativeViewHostWrapper implementation:
void NativeViewHostAura::AttachNativeView() {
if (!clipping_window_)
CreateClippingWindow();
clipping_window_delegate_->set_native_view(host_->native_view());
host_->native_view()->AddObserver(this);
host_->native_view()->SetProperty(views::kHostViewKey,
Expand Down Expand Up @@ -202,18 +192,17 @@ void NativeViewHostAura::ShowWidget(int x,
}
}

clipping_window_.SetBounds(clip_rect_ ? *clip_rect_
: gfx::Rect(x, y, w, h));
gfx::Point clip_offset = clipping_window_.bounds().origin();
clipping_window_->SetBounds(clip_rect_ ? *clip_rect_ : gfx::Rect(x, y, w, h));
gfx::Point clip_offset = clipping_window_->bounds().origin();
host_->native_view()->SetBounds(
gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), native_w, native_h));
host_->native_view()->Show();
clipping_window_.Show();
clipping_window_->Show();
}

void NativeViewHostAura::HideWidget() {
host_->native_view()->Hide();
clipping_window_.Hide();
clipping_window_->Hide();
}

void NativeViewHostAura::SetFocus() {
Expand Down Expand Up @@ -265,35 +254,48 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
return new NativeViewHostAura(host);
}

void NativeViewHostAura::CreateClippingWindow() {
clipping_window_delegate_ = std::make_unique<ClippingWindowDelegate>();
// Use WINDOW_TYPE_CONTROLLER type so descendant views (including popups) get
// positioned appropriately.
clipping_window_ = std::make_unique<aura::Window>(
clipping_window_delegate_.get(), aura::client::WINDOW_TYPE_CONTROL,
host_->native_view()->env());
clipping_window_->Init(ui::LAYER_NOT_DRAWN);
clipping_window_->set_owned_by_parent(false);
clipping_window_->SetName("NativeViewHostAuraClip");
clipping_window_->layer()->SetMasksToBounds(true);
clipping_window_->SetProperty(views::kHostViewKey, static_cast<View*>(host_));
}

void NativeViewHostAura::AddClippingWindow() {
RemoveClippingWindow();

host_->native_view()->SetProperty(aura::client::kHostWindowKey,
host_->GetWidget()->GetNativeView());
Widget::ReparentNativeView(host_->native_view(),
&clipping_window_);
Widget::ReparentNativeView(host_->native_view(), clipping_window_.get());
if (host_->GetWidget()->GetNativeView()) {
Widget::ReparentNativeView(&clipping_window_,
Widget::ReparentNativeView(clipping_window_.get(),
host_->GetWidget()->GetNativeView());
}
}

void NativeViewHostAura::RemoveClippingWindow() {
clipping_window_.Hide();
clipping_window_->Hide();
if (host_->native_view())
host_->native_view()->ClearProperty(aura::client::kHostWindowKey);

if (host_->native_view()->parent() == &clipping_window_) {
if (host_->native_view()->parent() == clipping_window_.get()) {
if (host_->GetWidget() && host_->GetWidget()->GetNativeView()) {
Widget::ReparentNativeView(host_->native_view(),
host_->GetWidget()->GetNativeView());
} else {
clipping_window_.RemoveChild(host_->native_view());
clipping_window_->RemoveChild(host_->native_view());
}
host_->native_view()->SetBounds(clipping_window_.bounds());
host_->native_view()->SetBounds(clipping_window_->bounds());
}
if (clipping_window_.parent())
clipping_window_.parent()->RemoveChild(&clipping_window_);
if (clipping_window_->parent())
clipping_window_->parent()->RemoveChild(clipping_window_.get());
}

void NativeViewHostAura::InstallMask() {
Expand Down
9 changes: 7 additions & 2 deletions ui/views/controls/native/native_view_host_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

#include "base/compiler_specific.h"
#include "base/macros.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/compositor/layer_owner.h"
#include "ui/gfx/transform.h"
#include "ui/views/controls/native/native_view_host_wrapper.h"
#include "ui/views/views_export.h"

namespace aura {
class Window;
}

namespace views {

class NativeViewHost;
Expand Down Expand Up @@ -53,6 +56,8 @@ class NativeViewHostAura : public NativeViewHostWrapper,
const gfx::Rect& new_bounds,
ui::PropertyChangeReason reason) override;

void CreateClippingWindow();

// Reparents the native view with the clipping window existing between it and
// its old parent, so that the fast resize path works.
void AddClippingWindow();
Expand All @@ -75,7 +80,7 @@ class NativeViewHostAura : public NativeViewHostWrapper,
// Window that exists between the native view and the parent that allows for
// clipping to occur. This is positioned in the coordinate space of
// host_->GetWidget().
aura::Window clipping_window_;
std::unique_ptr<aura::Window> clipping_window_;
std::unique_ptr<gfx::Rect> clip_rect_;

// This mask exists for the sake of SetCornerRadius().
Expand Down
4 changes: 3 additions & 1 deletion ui/views/controls/native/native_view_host_aura_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class NativeViewHostAuraTest : public test::NativeViewHostTestBase {
return child_.get();
}

aura::Window* clipping_window() { return &(native_host()->clipping_window_); }
aura::Window* clipping_window() {
return native_host()->clipping_window_.get();
}

void CreateHost() {
CreateTopLevel();
Expand Down
6 changes: 6 additions & 0 deletions ui/views/widget/desktop_aura/desktop_native_widget_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_occlusion_tracker.h"
Expand Down Expand Up @@ -912,6 +913,11 @@ bool DesktopNativeWidgetAura::IsMouseEventsEnabled() const {
return cursor_client ? cursor_client->IsMouseEventsEnabled() : true;
}

bool DesktopNativeWidgetAura::IsMouseButtonDown() const {
return content_window_ ? content_window_->env()->IsMouseButtonDown()
: aura::Env::GetInstance()->IsMouseButtonDown();
}

void DesktopNativeWidgetAura::ClearNativeFocus() {
desktop_window_tree_host_->ClearNativeFocus();

Expand Down
1 change: 1 addition & 0 deletions ui/views/widget/desktop_aura/desktop_native_widget_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
void SchedulePaintInRect(const gfx::Rect& rect) override;
void SetCursor(gfx::NativeCursor cursor) override;
bool IsMouseEventsEnabled() const override;
bool IsMouseButtonDown() const override;
void ClearNativeFocus() override;
gfx::Rect GetWorkAreaBoundsInScreen() const override;
Widget::MoveLoopResult RunMoveLoop(
Expand Down
5 changes: 4 additions & 1 deletion ui/views/widget/native_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#ifndef UI_VIEWS_WIDGET_NATIVE_WIDGET_H_
#define UI_VIEWS_WIDGET_NATIVE_WIDGET_H_

#include "ui/views/widget/widget.h"
#include "ui/views/views_export.h"

namespace views {

class Widget;

namespace internal {
class NativeWidgetPrivate;
}
Expand Down
24 changes: 16 additions & 8 deletions ui/views/widget/native_widget_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ void SetIcon(aura::Window* window,
// NativeWidgetAura, public:

NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate,
bool is_parallel_widget_in_window_manager)
bool is_parallel_widget_in_window_manager,
aura::Env* env)
: delegate_(delegate),
is_parallel_widget_in_window_manager_(
is_parallel_widget_in_window_manager),
window_(new aura::Window(this)),
window_(new aura::Window(this, aura::client::WINDOW_TYPE_UNKNOWN, env)),
ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
destroying_(false),
cursor_(gfx::kNullCursor),
Expand Down Expand Up @@ -707,6 +708,11 @@ bool NativeWidgetAura::IsMouseEventsEnabled() const {
return cursor_client ? cursor_client->IsMouseEventsEnabled() : true;
}

bool NativeWidgetAura::IsMouseButtonDown() const {
return window_ ? window_->env()->IsMouseButtonDown()
: aura::Env::GetInstance()->IsMouseButtonDown();
}

void NativeWidgetAura::ClearNativeFocus() {
aura::client::FocusClient* client = aura::client::GetFocusClient(window_);
if (window_ && client && window_->Contains(client->GetFocusedWindow()))
Expand Down Expand Up @@ -1087,8 +1093,15 @@ namespace internal {

// static
NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
const Widget::InitParams& init_params,
internal::NativeWidgetDelegate* delegate) {
return new NativeWidgetAura(delegate);
aura::Env* env = nullptr;
if (init_params.parent)
env = init_params.parent->env();
else if (init_params.context)
env = init_params.context->env();
return new NativeWidgetAura(
delegate, /*is_parallel_widget_in_window_manager*/ false, env);
}

// static
Expand Down Expand Up @@ -1197,11 +1210,6 @@ void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
}
}

// static
bool NativeWidgetPrivate::IsMouseButtonDown() {
return aura::Env::GetInstance()->IsMouseButtonDown();
}

// static
gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() {
#if defined(OS_WIN)
Expand Down
5 changes: 4 additions & 1 deletion ui/views/widget/native_widget_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ui/wm/public/activation_delegate.h"

namespace aura {
class Env;
class Window;
}

Expand All @@ -43,7 +44,8 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
// NativeWidgetAura is created in the window manager to represent a client
// window, in all other cases it's false.
explicit NativeWidgetAura(internal::NativeWidgetDelegate* delegate,
bool is_parallel_widget_in_window_manager = false);
bool is_parallel_widget_in_window_manager = false,
aura::Env* env = nullptr);

// Called internally by NativeWidgetAura and DesktopNativeWidgetAura to
// associate |native_widget| with |window|.
Expand Down Expand Up @@ -133,6 +135,7 @@ class VIEWS_EXPORT NativeWidgetAura : public internal::NativeWidgetPrivate,
void SchedulePaintInRect(const gfx::Rect& rect) override;
void SetCursor(gfx::NativeCursor cursor) override;
bool IsMouseEventsEnabled() const override;
bool IsMouseButtonDown() const override;
void ClearNativeFocus() override;
gfx::Rect GetWorkAreaBoundsInScreen() const override;
Widget::MoveLoopResult RunMoveLoop(
Expand Down
1 change: 1 addition & 0 deletions ui/views/widget/native_widget_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class VIEWS_EXPORT NativeWidgetMac : public internal::NativeWidgetPrivate {
void SchedulePaintInRect(const gfx::Rect& rect) override;
void SetCursor(gfx::NativeCursor cursor) override;
bool IsMouseEventsEnabled() const override;
bool IsMouseButtonDown() const override;
void ClearNativeFocus() override;
gfx::Rect GetWorkAreaBoundsInScreen() const override;
Widget::MoveLoopResult RunMoveLoop(
Expand Down
10 changes: 5 additions & 5 deletions ui/views/widget/native_widget_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,10 @@ NSInteger StyleMaskForParams(const Widget::InitParams& params) {
return true;
}

bool NativeWidgetMac::IsMouseButtonDown() const {
return [NSEvent pressedMouseButtons] != 0;
}

void NativeWidgetMac::ClearNativeFocus() {
// To quote DesktopWindowTreeHostX11, "This method is weird and misnamed."
// The goal is to set focus to the content window, thereby removing focus from
Expand Down Expand Up @@ -712,6 +716,7 @@ NSInteger StyleMaskForParams(const Widget::InitParams& params) {

// static
NativeWidgetPrivate* NativeWidgetPrivate::CreateNativeWidget(
const Widget::InitParams& init_params,
internal::NativeWidgetDelegate* delegate) {
return new NativeWidgetMac(delegate);
}
Expand Down Expand Up @@ -844,11 +849,6 @@ NSInteger StyleMaskForParams(const Widget::InitParams& params) {
child->NotifyNativeViewHierarchyChanged();
}

// static
bool NativeWidgetPrivate::IsMouseButtonDown() {
return [NSEvent pressedMouseButtons] != 0;
}

// static
gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() {
NOTIMPLEMENTED();
Expand Down
7 changes: 4 additions & 3 deletions ui/views/widget/native_widget_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "ui/base/ui_base_types.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/widget/native_widget.h"
#include "ui/views/widget/widget.h"

namespace gfx {
class FontList;
Expand Down Expand Up @@ -49,6 +50,7 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
// Creates an appropriate default NativeWidgetPrivate implementation for the
// current OS/circumstance.
static NativeWidgetPrivate* CreateNativeWidget(
const Widget::InitParams& init_params,
internal::NativeWidgetDelegate* delegate);

static NativeWidgetPrivate* GetNativeWidgetForNativeView(
Expand All @@ -68,9 +70,6 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
static void ReparentNativeView(gfx::NativeView native_view,
gfx::NativeView new_parent);

// Returns true if any mouse button is currently down.
static bool IsMouseButtonDown();

static gfx::FontList GetWindowTitleFontList();

// Returns the NativeView with capture, otherwise NULL if there is no current
Expand Down Expand Up @@ -216,6 +215,8 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget {
virtual void SchedulePaintInRect(const gfx::Rect& rect) = 0;
virtual void SetCursor(gfx::NativeCursor cursor) = 0;
virtual bool IsMouseEventsEnabled() const = 0;
// Returns true if any mouse button is currently down.
virtual bool IsMouseButtonDown() const = 0;
virtual void ClearNativeFocus() = 0;
virtual gfx::Rect GetWorkAreaBoundsInScreen() const = 0;
virtual Widget::MoveLoopResult RunMoveLoop(
Expand Down
Loading

0 comments on commit b283bc8

Please sign in to comment.