Commit 5b19be3a authored by sky's avatar sky Committed by Commit bot

Makes NativeViewport send OnBoundsChanged() after widget available

It was possible for us to send it before.

BUG=none
TEST=none
R=ben@chromium.org, darin@chromium.org

Review URL: https://codereview.chromium.org/617513003

Cr-Commit-Position: refs/heads/master@{#297472}
parent e650b32b
......@@ -47,6 +47,10 @@ class Callback<void()> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......@@ -86,6 +90,10 @@ class Callback<void(A1)> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......@@ -133,6 +141,10 @@ class Callback<void(A1, A2)> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......@@ -187,6 +199,10 @@ class Callback<void(A1, A2, A3)> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......@@ -246,6 +262,10 @@ class Callback<void(A1, A2, A3, A4)> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......@@ -310,6 +330,10 @@ class Callback<void(A1, A2, A3, A4, A5)> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......@@ -380,6 +404,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6)> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......@@ -455,6 +483,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6, A7)> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......
......@@ -63,6 +63,10 @@ class Callback<void($for ARG , [[A$(ARG)]])> {
return !sink_.get();
}
void reset() {
sink_.reset();
}
private:
template <typename Sink>
struct Adapter : public Runnable {
......
......@@ -31,6 +31,10 @@ class SharedPtr {
return impl_.value().ptr;
}
void reset() {
impl_.reset();
}
P* operator->() { return get(); }
const P* operator->() const { return get(); }
......
......@@ -4,6 +4,7 @@
#include "mojo/services/native_viewport/native_viewport_impl.h"
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
......@@ -48,13 +49,12 @@ NativeViewportImpl::~NativeViewportImpl() {
void NativeViewportImpl::Create(SizePtr size,
const Callback<void(uint64_t)>& callback) {
create_callback_ = callback;
size_ = size.To<gfx::Size>();
if (is_headless_)
platform_viewport_ = PlatformViewportHeadless::Create(this);
else
platform_viewport_ = PlatformViewport::Create(this);
const gfx::Rect bounds(gfx::Rect(size.To<gfx::Size>()));
platform_viewport_->Init(bounds);
OnBoundsChanged(bounds);
platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>()));
}
void NativeViewportImpl::Show() {
......@@ -94,10 +94,14 @@ void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) {
}
void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) {
if (size_ == bounds.size())
return;
size_ = bounds.size();
client()->OnSizeChanged(Size::From(size_));
if (viewport_surface_)
viewport_surface_->SetSize(size_);
// Wait for the accelerated widget before telling the client of the bounds.
if (create_callback_.is_null())
ProcessOnBoundsChanged();
}
void NativeViewportImpl::OnAcceleratedWidgetAvailable(
......@@ -105,6 +109,10 @@ void NativeViewportImpl::OnAcceleratedWidgetAvailable(
widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget));
// TODO(jamesr): Remove once everything is converted to surfaces.
create_callback_.Run(widget_id_);
create_callback_.reset();
// Immediately tell the client of the size. The size may be wrong, if so we'll
// get the right one in the next OnBoundsChanged() call.
ProcessOnBoundsChanged();
if (viewport_surface_)
viewport_surface_->SetWidgetId(widget_id_);
}
......@@ -142,5 +150,11 @@ void NativeViewportImpl::AckEvent() {
waiting_for_event_ack_ = false;
}
void NativeViewportImpl::ProcessOnBoundsChanged() {
client()->OnSizeChanged(Size::From(size_));
if (viewport_surface_)
viewport_surface_->SetSize(size_);
}
} // namespace mojo
......@@ -46,6 +46,8 @@ class NativeViewportImpl : public InterfaceImpl<NativeViewport>,
void AckEvent();
private:
void ProcessOnBoundsChanged();
bool is_headless_;
scoped_ptr<PlatformViewport> platform_viewport_;
scoped_ptr<ViewportSurface> viewport_surface_;
......
......@@ -13,7 +13,6 @@ module mojo {
interface NativeViewport {
// TODO(sky): having a create function is awkward. Should there be a factory
// to create the NativeViewport that takes the size?
// TODO(sky): callback should take size too.
Create(Size size) => (uint64 native_viewport_id);
Show();
Hide();
......@@ -23,6 +22,8 @@ interface NativeViewport {
};
interface NativeViewportClient {
// OnSizeChanged() is sent at least once after the callback from Create() is
// called.
OnSizeChanged(Size size);
OnDestroyed();
OnEvent(Event event) => ();
......
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