提交 8031ab6b 编写于 作者: A Adam Barth

Add padding values to View.idl

Rather than hardcoding the size and presence of the notification area in Dart,
we now expose padding values on the view. These values are set to non-zero
values when there are UI elements that overlap the view. We currently respect
only the top padding, but this CL paves the way to respect padding in other
directions.

We still hardcode the size of the notification area in Java. A future CL will
retrieve this value from the Android framework.

Fixes #257

R=ianh@google.com

Review URL: https://codereview.chromium.org/1220353002.
上级 13dc6e21
......@@ -25,6 +25,12 @@ public:
static PassRefPtr<View> create(const base::Closure& scheduleFrameCallback);
double devicePixelRatio() const { return m_displayMetrics.device_pixel_ratio; }
double paddingTop() const { return m_displayMetrics.padding_top; }
double paddingRight() const { return m_displayMetrics.padding_right; }
double paddingBottom() const { return m_displayMetrics.padding_bottom; }
double paddingLeft() const { return m_displayMetrics.padding_left; }
double width() const;
double height() const;
......
......@@ -5,6 +5,11 @@
interface View {
readonly attribute double devicePixelRatio;
readonly attribute double paddingTop;
readonly attribute double paddingRight;
readonly attribute double paddingBottom;
readonly attribute double paddingLeft;
// TODO(ianh): convert this to returning a Size
readonly attribute double width;
readonly attribute double height;
......
......@@ -12,6 +12,10 @@ namespace blink {
struct SkyDisplayMetrics {
WebSize physical_size;
float device_pixel_ratio = 1.0;
double padding_top = 0.0;
double padding_right = 0.0;
double padding_bottom = 0.0;
double padding_left = 0.0;
};
} // namespace blink
......
......@@ -5,7 +5,6 @@
// Modeled after Android's ViewConfiguration:
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewConfiguration.java
const double kNotificationAreaHeight = 25.0;
// TODO(ianh): Figure out actual specced height for status bar
const double kStatusBarHeight = 50.0;
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:sky' as sky;
import '../rendering/box.dart';
import '../rendering/object.dart';
import '../theme/view_configuration.dart';
......@@ -102,7 +104,7 @@ class RenderScaffold extends RenderBox {
}
if (_slots[ScaffoldSlots.toolbar] != null) {
RenderBox toolbar = _slots[ScaffoldSlots.toolbar];
double toolbarHeight = kToolBarHeight + kNotificationAreaHeight;
double toolbarHeight = kToolBarHeight + sky.view.paddingTop;
toolbar.layout(new BoxConstraints.tight(new Size(size.width, toolbarHeight)));
assert(toolbar.parentData is BoxParentData);
toolbar.parentData.position = Point.origin;
......
......@@ -6,8 +6,18 @@ module sky;
import "sky/services/engine/input_event.mojom";
struct ViewportMetrics {
int32 physical_width;
int32 physical_height;
float device_pixel_ratio = 1.0;
double padding_top;
double padding_right;
double padding_bottom;
double padding_left;
};
interface SkyEngine {
OnViewportMetricsChanged(int32 width, int32 height, float device_pixel_ratio);
OnViewportMetricsChanged(ViewportMetrics metrics);
OnInputEvent(InputEvent event);
RunFromNetwork(string url);
......
......@@ -24,6 +24,7 @@ import org.chromium.mojom.sky.InputEvent;
import org.chromium.mojom.sky.PointerData;
import org.chromium.mojom.sky.PointerKind;
import org.chromium.mojom.sky.SkyEngine;
import org.chromium.mojom.sky.ViewportMetrics;
/**
* A view containing Sky
......@@ -37,9 +38,21 @@ public class PlatformViewAndroid extends SurfaceView
private SkyEngine.Proxy mSkyEngine;
private final SurfaceHolder.Callback mSurfaceCallback;
private GestureProvider mGestureProvider;
private final EdgeDims mPadding;
/**
* Dimensions in each of the four cardinal directions.
*/
public static class EdgeDims {
public double top = 0.0;
public double right = 0.0;
public double bottom = 0.0;
public double left = 0.0;
}
public PlatformViewAndroid(Context context) {
public PlatformViewAndroid(Context context, EdgeDims padding) {
super(context);
mPadding = padding;
setFocusable(true);
setFocusableInTouchMode(true);
......@@ -53,7 +66,17 @@ public class PlatformViewAndroid extends SurfaceView
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
assert mSkyEngine != null;
mSkyEngine.onViewportMetricsChanged(width, height, density);
ViewportMetrics metrics = new ViewportMetrics();
metrics.physicalWidth = width;
metrics.physicalHeight = height;
metrics.devicePixelRatio = density;
if (mPadding != null) {
metrics.paddingTop = mPadding.top;
metrics.paddingRight = mPadding.right;
metrics.paddingBottom = mPadding.bottom;
metrics.paddingLeft = mPadding.left;
}
mSkyEngine.onViewportMetricsChanged(metrics);
}
@Override
......
......@@ -28,16 +28,20 @@ public class SkyActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PlatformViewAndroid.EdgeDims edgeDims = new PlatformViewAndroid.EdgeDims();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(0x40000000);
// TODO(abarth): We should get this value from the Android framework somehow.
edgeDims.top = 25.0;
}
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
SkyMain.ensureInitialized(getApplicationContext());
mView = new PlatformViewAndroid(this);
mView = new PlatformViewAndroid(this, edgeDims);
setContentView(mView);
mTracingController = new TracingController(this);
......
......@@ -86,8 +86,11 @@ static sky::InputEventPtr BasicInputEventFromRecognizer(
CGSize size = self.bounds.size;
CGFloat scale = [UIScreen mainScreen].scale;
_sky_engine->OnViewportMetricsChanged(size.width * scale,
size.height * scale, scale);
ViewportMetricsPtr metrics = ViewportMetrics::New();
metrics->physical_width = size.width * scale;
metrics->physical_height = size.height * scale;
metrics->device_pixel_ratio = scale;
_sky_engine->OnViewportMetricsChanged(metrics.Pass());
}
- (void)configureLayerDefaults {
......
......@@ -61,7 +61,10 @@ TestRunner::TestRunner()
CHECK(!g_test_runner) << "Only create one TestRunner.";
shell_view_->view()->ConnectToEngine(GetProxy(&sky_engine_));
sky_engine_->OnViewportMetricsChanged(320, 640, 1.0);
ViewportMetricsPtr metrics = ViewportMetrics::New();
metrics->physical_width = 320;
metrics->physical_height = 640;
sky_engine_->OnViewportMetricsChanged(metrics.Pass());
}
TestRunner::~TestRunner() {
......
......@@ -58,7 +58,6 @@ Engine::Config::~Config() {
Engine::Engine(const Config& config)
: config_(config),
animator_(new Animator(config, this)),
device_pixel_ratio_(1.0f),
binding_(this),
weak_factory_(this) {
}
......@@ -102,7 +101,8 @@ skia::RefPtr<SkPicture> Engine::Paint() {
if (sky_view_) {
skia::RefPtr<SkPicture> picture = sky_view_->Paint();
canvas->clear(SK_ColorBLACK);
canvas->scale(device_pixel_ratio_, device_pixel_ratio_);
canvas->scale(display_metrics_.device_pixel_ratio,
display_metrics_.device_pixel_ratio);
if (picture)
canvas->drawPicture(picture.get());
}
......@@ -128,27 +128,24 @@ void Engine::OnOutputSurfaceDestroyed() {
base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate));
}
void Engine::OnViewportMetricsChanged(int width, int height,
float device_pixel_ratio) {
physical_size_.SetSize(width, height);
device_pixel_ratio_ = device_pixel_ratio;
void Engine::OnViewportMetricsChanged(ViewportMetricsPtr metrics) {
physical_size_.SetSize(metrics->physical_width, metrics->physical_height);
if (sky_view_)
UpdateSkyViewSize();
}
display_metrics_.physical_size = physical_size_;
display_metrics_.device_pixel_ratio = metrics->device_pixel_ratio;
display_metrics_.padding_top = metrics->padding_top;
display_metrics_.padding_right = metrics->padding_right;
display_metrics_.padding_bottom = metrics->padding_bottom;
display_metrics_.padding_left = metrics->padding_left;
void Engine::UpdateSkyViewSize() {
CHECK(sky_view_);
blink::SkyDisplayMetrics metrics;
metrics.physical_size = physical_size_;
metrics.device_pixel_ratio = device_pixel_ratio_;
sky_view_->SetDisplayMetrics(metrics);
if (sky_view_)
sky_view_->SetDisplayMetrics(display_metrics_);
}
void Engine::OnInputEvent(InputEventPtr event) {
TRACE_EVENT0("sky", "Engine::OnInputEvent");
scoped_ptr<blink::WebInputEvent> web_event =
ConvertEvent(event, device_pixel_ratio_);
ConvertEvent(event, display_metrics_.device_pixel_ratio);
if (!web_event)
return;
if (sky_view_)
......@@ -159,7 +156,7 @@ void Engine::RunFromLibrary(const std::string& name) {
sky_view_ = blink::SkyView::Create(this);
sky_view_->RunFromLibrary(blink::WebString::fromUTF8(name),
dart_library_provider_.get());
UpdateSkyViewSize();
sky_view_->SetDisplayMetrics(display_metrics_);
}
void Engine::RunFromSnapshotStream(
......@@ -167,7 +164,7 @@ void Engine::RunFromSnapshotStream(
mojo::ScopedDataPipeConsumerHandle snapshot) {
sky_view_ = blink::SkyView::Create(this);
sky_view_->RunFromSnapshot(blink::WebString::fromUTF8(name), snapshot.Pass());
UpdateSkyViewSize();
sky_view_->SetDisplayMetrics(display_metrics_);
}
void Engine::RunFromNetwork(const mojo::String& url) {
......
......@@ -62,8 +62,7 @@ class Engine : public UIDelegate,
void OnOutputSurfaceDestroyed() override;
// SkyEngine implementation:
void OnViewportMetricsChanged(int width, int height,
float device_pixel_ratio) override;
void OnViewportMetricsChanged(ViewportMetricsPtr metrics) override;
void OnInputEvent(InputEventPtr event) override;
void RunFromNetwork(const mojo::String& url) override;
......@@ -89,8 +88,6 @@ class Engine : public UIDelegate,
void RunFromSnapshotStream(const std::string& name,
mojo::ScopedDataPipeConsumerHandle snapshot);
void UpdateSkyViewSize();
Config config_;
scoped_ptr<Animator> animator_;
......@@ -98,8 +95,8 @@ class Engine : public UIDelegate,
scoped_ptr<blink::DartLibraryProvider> dart_library_provider_;
std::unique_ptr<blink::SkyView> sky_view_;
float device_pixel_ratio_;
gfx::Size physical_size_;
blink::SkyDisplayMetrics display_metrics_;
mojo::Binding<SkyEngine> binding_;
base::WeakPtrFactory<Engine> weak_factory_;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册