Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Unified Diff: services/native_viewport/platform_viewport_ozone.cc

Issue 1309273005: native_viewport support for ozone (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/native_viewport/platform_viewport_ozone.cc
diff --git a/services/native_viewport/platform_viewport_ozone.cc b/services/native_viewport/platform_viewport_ozone.cc
deleted file mode 100644
index 69cba34157d6890f6fb026d07772b38abdc0c2fd..0000000000000000000000000000000000000000
--- a/services/native_viewport/platform_viewport_ozone.cc
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "services/native_viewport/platform_viewport.h"
-
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/input_events/input_events_type_converters.h"
-#include "mojo/converters/input_events/mojo_extended_key_event_data.h"
-#include "ui/events/event.h"
-#include "ui/events/platform/platform_event_dispatcher.h"
-#include "ui/events/platform/platform_event_source.h"
-#include "ui/ozone/public/cursor_factory_ozone.h"
-#include "ui/ozone/public/ozone_platform.h"
-#include "ui/ozone/public/surface_factory_ozone.h"
-#include "ui/platform_window/platform_window.h"
-#include "ui/platform_window/platform_window_delegate.h"
-
-namespace native_viewport {
-namespace {
-
-float ConvertUIWheelValueToMojoValue(int offset) {
- // Mojo's event type takes a value between -1 and 1. Normalize by allowing
- // up to 20 of ui's offset. This is a bit arbitrary.
- return std::max(
- -1.0f, std::min(1.0f, static_cast<float>(offset) /
- (20 * static_cast<float>(
- ui::MouseWheelEvent::kWheelDelta))));
-}
-} // namespace
-
-// TODO(spang): Deduplicate with PlatformViewportX11.. but there's a hack
-// in there that prevents this.
-class PlatformViewportOzone : public PlatformViewport,
- public ui::PlatformWindowDelegate {
- public:
- explicit PlatformViewportOzone(Delegate* delegate) : delegate_(delegate) {
- ui::OzonePlatform::InitializeForUI();
- }
-
- ~PlatformViewportOzone() override {
- // Destroy the platform-window while |this| is still alive.
- platform_window_.reset();
- }
-
- private:
- // Overridden from PlatformViewport:
- void Init(const gfx::Rect& bounds) override {
- platform_window_ =
- ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds);
-
- metrics_ = mojo::ViewportMetrics::New();
- metrics_->size = mojo::Size::From(bounds.size());
- }
-
- void Show() override { platform_window_->Show(); }
-
- void Hide() override { platform_window_->Hide(); }
-
- void Close() override { platform_window_->Close(); }
-
- gfx::Size GetSize() override {
- return platform_window_->GetBounds().size();
- }
-
- void SetBounds(const gfx::Rect& bounds) override {
- platform_window_->SetBounds(bounds);
- }
-
- // ui::PlatformWindowDelegate:
- void OnBoundsChanged(const gfx::Rect& new_bounds) override {
- metrics_->size = mojo::Size::From(new_bounds.size());
- delegate_->OnMetricsChanged(metrics_.Clone());
- }
-
- void OnDamageRect(const gfx::Rect& damaged_region) override {}
-
- void DispatchEvent(ui::Event* event) override {
- mojo::EventPtr mojo_event(mojo::Event::From(*event));
- if (event->IsMouseWheelEvent()) {
- // Mojo's event type has a different meaning for wheel events. Convert
- // between the two.
- ui::MouseWheelEvent* wheel_event =
- static_cast<ui::MouseWheelEvent*>(event);
- DCHECK(mojo_event->pointer_data);
- mojo_event->pointer_data->horizontal_wheel =
- ConvertUIWheelValueToMojoValue(wheel_event->x_offset());
- mojo_event->pointer_data->horizontal_wheel =
- ConvertUIWheelValueToMojoValue(wheel_event->y_offset());
- }
- delegate_->OnEvent(mojo_event.Pass());
-
- switch (event->type()) {
- case ui::ET_MOUSE_PRESSED:
- case ui::ET_TOUCH_PRESSED:
- platform_window_->SetCapture();
- break;
- case ui::ET_MOUSE_RELEASED:
- case ui::ET_TOUCH_RELEASED:
- platform_window_->ReleaseCapture();
- break;
- default:
- break;
- }
- }
-
- void OnCloseRequest() override { platform_window_->Close(); }
-
- void OnClosed() override { delegate_->OnDestroyed(); }
-
- void OnWindowStateChanged(ui::PlatformWindowState state) override {}
-
- void OnLostCapture() override {}
-
- void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override {
- delegate_->OnAcceleratedWidgetAvailable(widget);
- }
-
- void OnActivationChanged(bool active) override {}
-
- scoped_ptr<ui::PlatformWindow> platform_window_;
- Delegate* delegate_;
- mojo::ViewportMetricsPtr metrics_;
-
- DISALLOW_COPY_AND_ASSIGN(PlatformViewportOzone);
-};
-
-// static
-scoped_ptr<PlatformViewport> PlatformViewport::Create(
- mojo::ApplicationImpl* application_,
- Delegate* delegate) {
- return scoped_ptr<PlatformViewport>(
- new PlatformViewportOzone(delegate)).Pass();
-}
-
-} // namespace native_viewport

Powered by Google App Engine
This is Rietveld 408576698