Commit b921f3fc authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

exo: send surface's input region to mus

The surface input region doesn't work in mus and mash. This CL
implements WindowTargeter::GetExtraHitTestShapeRects() for
exo::Surface::window_. In mus and mash, this function will be called and
returned hittest rects will be sent to mus.

Bug: 766174
Change-Id: I67dc04cc331f0174ff3390920c3de98c00100df5
Reviewed-on: https://chromium-review.googlesource.com/685277
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: default avatarDavid Reveman <reveman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504758}
parent ce6abb81
...@@ -174,6 +174,16 @@ class CustomWindowTargeter : public aura::WindowTargeter { ...@@ -174,6 +174,16 @@ class CustomWindowTargeter : public aura::WindowTargeter {
return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1)));
} }
std::unique_ptr<HitTestRects> GetExtraHitTestShapeRects(
aura::Window* window) const override {
Surface* surface = Surface::AsSurface(window);
if (!surface)
return nullptr;
if (!surface->HasHitTestMask())
return nullptr;
return surface->GetHitTestShapeRects();
}
private: private:
DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter);
}; };
...@@ -572,6 +582,15 @@ void Surface::GetHitTestMask(gfx::Path* mask) const { ...@@ -572,6 +582,15 @@ void Surface::GetHitTestMask(gfx::Path* mask) const {
state_.input_region.getBoundaryPath(mask); state_.input_region.getBoundaryPath(mask);
} }
std::unique_ptr<aura::WindowTargeter::HitTestRects>
Surface::GetHitTestShapeRects() const {
auto rects = std::make_unique<aura::WindowTargeter::HitTestRects>();
SkRegion::Iterator it(state_.input_region);
for (const SkIRect& rect = it.rect(); !it.done(); it.next())
rects->push_back(gfx::SkIRectToRect(rect));
return rects;
}
void Surface::RegisterCursorProvider(Pointer* provider) { void Surface::RegisterCursorProvider(Pointer* provider) {
cursor_providers_.insert(provider); cursor_providers_.insert(provider);
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "third_party/skia/include/core/SkBlendMode.h" #include "third_party/skia/include/core/SkBlendMode.h"
#include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkRegion.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_targeter.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
...@@ -172,6 +173,11 @@ class Surface final : public ui::PropertyHandler { ...@@ -172,6 +173,11 @@ class Surface final : public ui::PropertyHandler {
// Returns the current input region of surface in the form of a hit-test mask. // Returns the current input region of surface in the form of a hit-test mask.
void GetHitTestMask(gfx::Path* mask) const; void GetHitTestMask(gfx::Path* mask) const;
// Returns the current input region of surface in the form of a set of
// hit-test rects.
std::unique_ptr<aura::WindowTargeter::HitTestRects> GetHitTestShapeRects()
const;
// Surface does not own cursor providers. It is the responsibility of the // Surface does not own cursor providers. It is the responsibility of the
// caller to remove the cursor provider before it is destroyed. // caller to remove the cursor provider before it is destroyed.
void RegisterCursorProvider(CursorProvider* provider); void RegisterCursorProvider(CursorProvider* provider);
......
...@@ -240,13 +240,69 @@ TEST_P(SurfaceTest, SetOpaqueRegion) { ...@@ -240,13 +240,69 @@ TEST_P(SurfaceTest, SetOpaqueRegion) {
} }
TEST_P(SurfaceTest, SetInputRegion) { TEST_P(SurfaceTest, SetInputRegion) {
std::unique_ptr<Surface> surface(new Surface); // Create a shell surface which size is 512x512.
auto surface = std::make_unique<Surface>();
auto shell_surface = std::make_unique<ShellSurface>(surface.get());
gfx::Size buffer_size(512, 512);
auto buffer = std::make_unique<Buffer>(
exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
surface->Attach(buffer.get());
surface->Commit();
EXPECT_FALSE(surface->HasHitTestMask());
// Setting a non-empty input region should succeed. {
surface->SetInputRegion(SkRegion(SkIRect::MakeWH(256, 256))); // Setting a non-empty input region should succeed.
surface->SetInputRegion(SkRegion(SkIRect::MakeWH(256, 256)));
surface->Commit();
std::unique_ptr<std::vector<gfx::Rect>> rects =
surface->GetHitTestShapeRects();
// The input region doesn't contain the surface, so we need hit test mask.
EXPECT_TRUE(surface->HasHitTestMask());
ASSERT_EQ(1u, rects->size());
ASSERT_EQ(gfx::Rect(256, 256), (*rects)[0]);
}
// Setting an empty input region should succeed. {
surface->SetInputRegion(SkRegion(SkIRect::MakeEmpty())); // Setting an empty input region should succeed.
surface->SetInputRegion(SkRegion(SkIRect::MakeEmpty()));
surface->Commit();
// The input region doesn't contain the surface, so we need hit test mask.
EXPECT_TRUE(surface->HasHitTestMask());
auto rects = surface->GetHitTestShapeRects();
EXPECT_TRUE(rects->empty());
}
{
// Setting an input region which contains the surface.
surface->SetInputRegion(SkRegion(SkIRect::MakeWH(512, 512)));
surface->Commit();
// The input region contains the surface, so we don't need hit test mask.
EXPECT_FALSE(surface->HasHitTestMask());
}
{
SkRegion region(SkIRect::MakeWH(512, 512));
region.op(SkIRect::MakeXYWH(0, 64, 64, 64), SkRegion::kDifference_Op);
region.op(SkIRect::MakeXYWH(88, 88, 12, 55), SkRegion::kDifference_Op);
region.op(SkIRect::MakeXYWH(100, 0, 33, 66), SkRegion::kDifference_Op);
// Setting a non-rectangle input region should succeed.
surface->SetInputRegion(SkRegion(region));
surface->Commit();
// The input region doesn't contain the surface, so we need hit test mask.
EXPECT_TRUE(surface->HasHitTestMask());
auto rects = surface->GetHitTestShapeRects();
ASSERT_EQ(10u, rects->size());
SkRegion result(SkIRect::MakeEmpty());
for (const auto& r : *rects)
result.op(gfx::RectToSkIRect(r), SkRegion::kUnion_Op);
ASSERT_EQ(result, region);
}
} }
TEST_P(SurfaceTest, SetBufferScale) { TEST_P(SurfaceTest, SetBufferScale) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment