Remove dependency on ui from view_manager.

This removes unnecessary dependencies like skia, freetype and many others. Instead of using geometry types from gfx, use the simple types already in mojo.

R=ben@chromium.org, sky@chromium.org

Review URL: https://codereview.chromium.org/658923003
diff --git a/mojo/aura/window_tree_host_mojo.cc b/mojo/aura/window_tree_host_mojo.cc
index 9f30e13..cd97fa8 100644
--- a/mojo/aura/window_tree_host_mojo.cc
+++ b/mojo/aura/window_tree_host_mojo.cc
@@ -5,6 +5,7 @@
 #include "mojo/aura/window_tree_host_mojo.h"
 
 #include "mojo/aura/surface_context_factory.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
 #include "mojo/public/interfaces/application/shell.mojom.h"
 #include "mojo/services/public/cpp/view_manager/view_manager.h"
 #include "ui/aura/env.h"
@@ -19,7 +20,7 @@
 // WindowTreeHostMojo, public:
 
 WindowTreeHostMojo::WindowTreeHostMojo(Shell* shell, View* view)
-    : view_(view), bounds_(view->bounds()) {
+    : view_(view), bounds_(view->bounds().To<gfx::Rect>()) {
   view_->AddObserver(this);
 
   context_factory_.reset(new SurfaceContextFactory(shell, view_));
@@ -107,12 +108,14 @@
 
 void WindowTreeHostMojo::OnViewBoundsChanged(
     View* view,
-    const gfx::Rect& old_bounds,
-    const gfx::Rect& new_bounds) {
-  bounds_ = new_bounds;
-  if (old_bounds.origin() != new_bounds.origin())
+    const Rect& old_bounds,
+    const Rect& new_bounds) {
+  gfx::Rect old_bounds2 = old_bounds.To<gfx::Rect>();
+  gfx::Rect new_bounds2 = new_bounds.To<gfx::Rect>();
+  bounds_ = new_bounds2;
+  if (old_bounds2.origin() != new_bounds2.origin())
     OnHostMoved(bounds_.origin());
-  if (old_bounds.size() != new_bounds.size())
+  if (old_bounds2.size() != new_bounds2.size())
     OnHostResized(bounds_.size());
 }
 
diff --git a/mojo/aura/window_tree_host_mojo.h b/mojo/aura/window_tree_host_mojo.h
index f3f4be9..097515e 100644
--- a/mojo/aura/window_tree_host_mojo.h
+++ b/mojo/aura/window_tree_host_mojo.h
@@ -56,8 +56,8 @@
 
   // ViewObserver:
   void OnViewBoundsChanged(View* view,
-                           const gfx::Rect& old_bounds,
-                           const gfx::Rect& new_bounds) override;
+                           const Rect& old_bounds,
+                           const Rect& new_bounds) override;
 
   View* view_;
 
diff --git a/mojo/converters/geometry/geometry_type_converters.cc b/mojo/converters/geometry/geometry_type_converters.cc
index 3830879..b87e2f1 100644
--- a/mojo/converters/geometry/geometry_type_converters.cc
+++ b/mojo/converters/geometry/geometry_type_converters.cc
@@ -109,4 +109,19 @@
   return transform;
 }
 
+// static
+Rect TypeConverter<Rect, gfx::Rect>::Convert(const gfx::Rect& input) {
+  Rect rect;
+  rect.x = input.x();
+  rect.y = input.y();
+  rect.width = input.width();
+  rect.height = input.height();
+  return rect;
+}
+
+// static
+gfx::Rect TypeConverter<gfx::Rect, Rect>::Convert(const Rect& input) {
+  return gfx::Rect(input.x, input.y, input.width, input.height);
+}
+
 }  // namespace mojo
diff --git a/mojo/converters/geometry/geometry_type_converters.h b/mojo/converters/geometry/geometry_type_converters.h
index ee9ea72..5d52374 100644
--- a/mojo/converters/geometry/geometry_type_converters.h
+++ b/mojo/converters/geometry/geometry_type_converters.h
@@ -69,6 +69,15 @@
   static gfx::Transform Convert(const TransformPtr& input);
 };
 
+template <>
+struct MOJO_GEOMETRY_EXPORT TypeConverter<Rect, gfx::Rect> {
+  static Rect Convert(const gfx::Rect& input);
+};
+template <>
+struct MOJO_GEOMETRY_EXPORT TypeConverter<gfx::Rect, Rect> {
+  static gfx::Rect Convert(const Rect& input);
+};
+
 }  // namespace mojo
 
 #endif  // MOJO_CONVERTERS_GEOMETRY_GEOMETRY_TYPE_CONVERTERS_H_
diff --git a/mojo/examples/bitmap_uploader/bitmap_uploader.cc b/mojo/examples/bitmap_uploader/bitmap_uploader.cc
index dfd7a7d..6a878ec 100644
--- a/mojo/examples/bitmap_uploader/bitmap_uploader.cc
+++ b/mojo/examples/bitmap_uploader/bitmap_uploader.cc
@@ -84,7 +84,7 @@
 }
 
 void BitmapUploader::Upload() {
-  const gfx::Size& size(view_->bounds().size());
+  const gfx::Size size(view_->bounds().width, view_->bounds().height);
   if (size.IsEmpty()) {
     view_->SetSurfaceId(SurfaceId::New());
     return;
diff --git a/mojo/examples/browser/browser.cc b/mojo/examples/browser/browser.cc
index e5f724e..9f88e51 100644
--- a/mojo/examples/browser/browser.cc
+++ b/mojo/examples/browser/browser.cc
@@ -194,7 +194,7 @@
         views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
     params.native_widget = new NativeWidgetViewManager(widget_, shell_, view);
     params.delegate = widget_delegate;
-    params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height());
+    params.bounds = gfx::Rect(view->bounds().width, view->bounds().height);
     widget_->Init(params);
     // KeyboardManager handles deleting itself when the widget is destroyed.
     new KeyboardManager(widget_, window_manager_.get(), view);
diff --git a/mojo/examples/keyboard/keyboard.cc b/mojo/examples/keyboard/keyboard.cc
index 3cd4a4e..d08b6ed 100644
--- a/mojo/examples/keyboard/keyboard.cc
+++ b/mojo/examples/keyboard/keyboard.cc
@@ -92,7 +92,7 @@
         views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
     params.native_widget = new NativeWidgetViewManager(widget, shell_, view);
     params.delegate = widget_delegate;
-    params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height());
+    params.bounds = gfx::Rect(view->bounds().width, view->bounds().height);
     widget->Init(params);
     widget->Show();
   }
diff --git a/mojo/examples/media_viewer/media_viewer.cc b/mojo/examples/media_viewer/media_viewer.cc
index 4d23a8e..c5dbd4d 100644
--- a/mojo/examples/media_viewer/media_viewer.cc
+++ b/mojo/examples/media_viewer/media_viewer.cc
@@ -164,7 +164,7 @@
         views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
     params.native_widget = new NativeWidgetViewManager(widget, shell, view);
     params.delegate = widget_delegate;
-    params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height());
+    params.bounds = gfx::Rect(view->bounds().width, view->bounds().height);
     params.opacity = views::Widget::InitParams::OPAQUE_WINDOW;
     widget->Init(params);
     widget->Show();
@@ -232,10 +232,14 @@
 
   void LayoutViews() {
     View* root = content_view_->parent();
-    gfx::Rect control_bounds(root->bounds().width(), 28);
+    Rect control_bounds;
+    control_bounds.width = root->bounds().width;
+    control_bounds.height = 28;
     control_view_->SetBounds(control_bounds);
-    gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(),
-                             root->bounds().height() - control_bounds.height());
+    Rect content_bounds;
+    content_bounds.y = control_bounds.height;
+    content_bounds.width = root->bounds().width;
+    content_bounds.height = root->bounds().height - control_bounds.height;
     content_view_->SetBounds(content_bounds);
   }
 
@@ -287,8 +291,8 @@
 
   // ViewObserver:
   virtual void OnViewBoundsChanged(View* view,
-                                   const gfx::Rect& old_bounds,
-                                   const gfx::Rect& new_bounds) override {
+                                   const Rect& old_bounds,
+                                   const Rect& new_bounds) override {
     LayoutViews();
   }
   virtual void OnViewDestroyed(View* view) override {
diff --git a/mojo/examples/nesting_app/nesting_app.cc b/mojo/examples/nesting_app/nesting_app.cc
index 4473d6f..7d281e4 100644
--- a/mojo/examples/nesting_app/nesting_app.cc
+++ b/mojo/examples/nesting_app/nesting_app.cc
@@ -69,7 +69,10 @@
 
     nested_ = View::Create(view_manager);
     root->AddChild(nested_);
-    nested_->SetBounds(gfx::Rect(20, 20, 50, 50));
+    Rect rect;
+    rect.x = rect.y = 20;
+    rect.width = rect.height = 50;
+    nested_->SetBounds(rect);
     nested_->Embed(kEmbeddedAppURL);
   }
   virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
diff --git a/mojo/examples/png_viewer/png_viewer.cc b/mojo/examples/png_viewer/png_viewer.cc
index b1110e0..42323a3 100644
--- a/mojo/examples/png_viewer/png_viewer.cc
+++ b/mojo/examples/png_viewer/png_viewer.cc
@@ -93,8 +93,8 @@
 
   // Overridden from ViewObserver:
   virtual void OnViewBoundsChanged(View* view,
-                                   const gfx::Rect& old_bounds,
-                                   const gfx::Rect& new_bounds) override {
+                                   const Rect& old_bounds,
+                                   const Rect& new_bounds) override {
     DCHECK_EQ(view, root_);
     DrawBitmap();
   }
@@ -135,7 +135,7 @@
       return;
 
     skia::RefPtr<SkCanvas> canvas(skia::AdoptRef(skia::CreatePlatformCanvas(
-        root_->bounds().width(), root_->bounds().height(), true)));
+        root_->bounds().width, root_->bounds().height, true)));
     canvas->drawColor(SK_ColorGRAY);
     SkPaint paint;
     SkScalar scale =
diff --git a/mojo/examples/window_manager/debug_panel.cc b/mojo/examples/window_manager/debug_panel.cc
index 4a75134..643155b 100644
--- a/mojo/examples/window_manager/debug_panel.cc
+++ b/mojo/examples/window_manager/debug_panel.cc
@@ -65,7 +65,7 @@
       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
   params.native_widget = new NativeWidgetViewManager(widget, shell, view);
   params.delegate = widget_delegate;
-  params.bounds = gfx::Rect(view->bounds().size());
+  params.bounds = gfx::Rect(0, 0, view->bounds().width, view->bounds().height);
   widget->Init(params);
   widget->Show();
 }
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index e2bb237..c36c829 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -155,7 +155,7 @@
   void Init(ApplicationImpl* application,
             ViewManager* view_manager,
             View* parent,
-            const gfx::Rect& bounds) {
+            const Rect& bounds) {
     view_manager_ = view_manager;
     view_ = View::Create(view_manager);
     view_->SetBounds(bounds);
@@ -166,7 +166,7 @@
     parent->AddObserver(this);
   }
 
-  void Show(Id view_id, const gfx::Rect& bounds) {
+  void Show(Id view_id, const Rect& bounds) {
     keyboard_service_->SetTarget(view_id);
     view_->SetVisible(true);
   }
@@ -188,12 +188,13 @@
 
   // Overridden from ViewObserver:
   virtual void OnViewBoundsChanged(View* parent,
-                                   const gfx::Rect& old_bounds,
-                                   const gfx::Rect& new_bounds) override {
-    gfx::Rect keyboard_bounds(view_->bounds());
-    keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height());
-    keyboard_bounds.set_width(keyboard_bounds.width() +
-                              new_bounds.width() - old_bounds.width());
+                                   const Rect& old_bounds,
+                                   const Rect& new_bounds) override {
+    Rect keyboard_bounds(view_->bounds());
+    keyboard_bounds.y =
+        new_bounds.y + new_bounds.height - keyboard_bounds.height;
+    keyboard_bounds.width =
+        keyboard_bounds.width + new_bounds.width - old_bounds.width;
     view_->SetBounds(keyboard_bounds);
   }
   virtual void OnViewDestroyed(View* parent) override {
@@ -231,26 +232,26 @@
  private:
   // Overridden from ViewObserver:
   virtual void OnViewBoundsChanged(View* view,
-                                   const gfx::Rect& old_bounds,
-                                   const gfx::Rect& new_bounds) override {
+                                   const Rect& old_bounds,
+                                   const Rect& new_bounds) override {
     DCHECK_EQ(view, root_);
 
     View* content_view = view_manager_->GetViewById(content_view_id_);
     content_view->SetBounds(new_bounds);
 
-    int delta_width = new_bounds.width() - old_bounds.width();
-    int delta_height = new_bounds.height() - old_bounds.height();
+    int delta_width = new_bounds.width - old_bounds.width;
+    int delta_height = new_bounds.height - old_bounds.height;
 
     View* launcher_ui_view =
         view_manager_->GetViewById(launcher_ui_view_id_);
-    gfx::Rect launcher_ui_bounds(launcher_ui_view->bounds());
-    launcher_ui_bounds.set_width(launcher_ui_bounds.width() + delta_width);
+    Rect launcher_ui_bounds(launcher_ui_view->bounds());
+    launcher_ui_bounds.width += delta_width;
     launcher_ui_view->SetBounds(launcher_ui_bounds);
 
     View* control_panel_view =
         view_manager_->GetViewById(control_panel_view_id_);
-    gfx::Rect control_panel_bounds(control_panel_view->bounds());
-    control_panel_bounds.set_x(control_panel_bounds.x() + delta_width);
+    Rect control_panel_bounds(control_panel_view->bounds());
+    control_panel_bounds.x += delta_width;
     control_panel_view->SetBounds(control_panel_bounds);
 
     const View::Children& content_views = content_view->children();
@@ -260,9 +261,9 @@
       if (view->id() == control_panel_view->id() ||
           view->id() == launcher_ui_view->id())
         continue;
-      gfx::Rect view_bounds(view->bounds());
-      view_bounds.set_width(view_bounds.width() + delta_width);
-      view_bounds.set_height(view_bounds.height() + delta_height);
+      Rect view_bounds(view->bounds());
+      view_bounds.width += delta_width;
+      view_bounds.height += delta_height;
       view->SetBounds(view_bounds);
     }
   }
@@ -339,7 +340,7 @@
     window->view()->Destroy();
   }
 
-  void ShowKeyboard(Id view_id, const gfx::Rect& bounds) {
+  void ShowKeyboard(Id view_id, const Rect& bounds) {
     // TODO: this needs to validate |view_id|. That is, it shouldn't assume
     // |view_id| is valid and it also needs to make sure the client that sent
     // this really owns |view_id|.
@@ -350,9 +351,11 @@
       int ideal_height = 200;
       // TODO(sky): 10 is a bit of a hack here. There is a bug that causes
       // white strips to appear when 0 is used. Figure this out!
-      const gfx::Rect keyboard_bounds(
-          10, parent->bounds().height() - ideal_height,
-          parent->bounds().width() - 20, ideal_height);
+      Rect keyboard_bounds;
+      keyboard_bounds.x =  10;
+      keyboard_bounds.y = parent->bounds().height - ideal_height;
+      keyboard_bounds.width = parent->bounds().width - 20;
+      keyboard_bounds.height = ideal_height;
       keyboard_manager_->Init(app_, view_manager_, parent, keyboard_bounds);
     }
     keyboard_manager_->Show(view_id, bounds);
@@ -409,7 +412,10 @@
 
     View* view = View::Create(view_manager_);
     root->AddChild(view);
-    view->SetBounds(gfx::Rect(root->bounds().size()));
+    Rect rect;
+    rect.width = root->bounds().width;
+    rect.height = root->bounds().height;
+    view->SetBounds(rect);
     content_view_id_ = view->id();
 
     Id launcher_ui_id = CreateLauncherUI();
@@ -486,9 +492,11 @@
   // TODO(beng): proper layout manager!!
   Id CreateLauncherUI() {
     View* view = view_manager_->GetViewById(content_view_id_);
-    gfx::Rect bounds = view->bounds();
-    bounds.Inset(kBorderInset, kBorderInset);
-    bounds.set_height(kTextfieldHeight);
+    Rect bounds = view->bounds();
+    bounds.x += kBorderInset;
+    bounds.y += kBorderInset;
+    bounds.width -= 2 * kBorderInset;
+    bounds.height = kTextfieldHeight;
     launcher_ui_ = CreateWindow(bounds);
     launcher_ui_->Embed("mojo:browser");
     return launcher_ui_->view()->id();
@@ -496,21 +504,20 @@
 
   Window* CreateWindow() {
     View* view = view_manager_->GetViewById(content_view_id_);
-    gfx::Rect bounds(kBorderInset,
-                     2 * kBorderInset + kTextfieldHeight,
-                     view->bounds().width() - 3 * kBorderInset -
-                         kControlPanelWidth,
-                     view->bounds().height() -
-                         (3 * kBorderInset + kTextfieldHeight));
+    Rect bounds;
+    bounds.x = kBorderInset;
+    bounds.y = 2 * kBorderInset + kTextfieldHeight;
+    bounds.width = view->bounds().width - 3 * kBorderInset - kControlPanelWidth;
+    bounds.height =
+        view->bounds().height - (3 * kBorderInset + kTextfieldHeight);
     if (!windows_.empty()) {
-      gfx::Point position = windows_.back()->view()->bounds().origin();
-      position.Offset(35, 35);
-      bounds.set_origin(position);
+      bounds.x = windows_.back()->view()->bounds().x + 35;
+      bounds.y = windows_.back()->view()->bounds().y + 35;
     }
     return CreateWindow(bounds);
   }
 
-  Window* CreateWindow(const gfx::Rect& bounds) {
+  Window* CreateWindow(const Rect& bounds) {
     View* content = view_manager_->GetViewById(content_view_id_);
     View* view = View::Create(view_manager_);
     content->AddChild(view);
@@ -528,12 +535,12 @@
     View* view = View::Create(view_manager_);
     root->AddChild(view);
 
-    gfx::Rect bounds(root->bounds().width() - kControlPanelWidth -
-                         kBorderInset,
-                     kBorderInset * 2 + kTextfieldHeight,
-                     kControlPanelWidth,
-                     root->bounds().height() - kBorderInset * 3 -
-                         kTextfieldHeight);
+    Rect bounds;
+    bounds.x = root->bounds().width - kControlPanelWidth - kBorderInset;
+    bounds.y = kBorderInset * 2 + kTextfieldHeight;
+    bounds.width = kControlPanelWidth;
+    bounds.height =
+        root->bounds().height - kBorderInset * 3 - kTextfieldHeight;
     view->SetBounds(bounds);
 
     debug_panel_ = new DebugPanel(this, shell_, view);
@@ -579,7 +586,7 @@
 }
 
 void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) {
-  window_manager_->ShowKeyboard(view_id, bounds.To<gfx::Rect>());
+  window_manager_->ShowKeyboard(view_id, *bounds);
 }
 
 void WindowManagerConnection::HideKeyboard(Id view_id) {
diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/app/app.cc
index d9a8da2..f9e996c 100644
--- a/mojo/examples/wm_flow/app/app.cc
+++ b/mojo/examples/wm_flow/app/app.cc
@@ -93,8 +93,10 @@
 
     mojo::View* embed = mojo::View::Create(view_manager);
     root->AddChild(embed);
-    gfx::Rect bounds = gfx::Rect(root->bounds().size());
-    bounds.Inset(25, 25);
+    mojo::Rect bounds;
+    bounds.x = bounds.y = 25;
+    bounds.width = root->bounds().width - 50;
+    bounds.height = root->bounds().height - 50;
     embed->SetBounds(bounds);
 
     scoped_ptr<mojo::ServiceProviderImpl> registry(
diff --git a/mojo/examples/wm_flow/wm/frame_controller.cc b/mojo/examples/wm_flow/wm/frame_controller.cc
index 40ff041..35ea7b4 100644
--- a/mojo/examples/wm_flow/wm/frame_controller.cc
+++ b/mojo/examples/wm_flow/wm/frame_controller.cc
@@ -6,6 +6,7 @@
 
 #include "base/macros.h"
 #include "base/strings/utf_string_conversions.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
 #include "mojo/services/public/cpp/view_manager/view.h"
 #include "mojo/services/window_manager/window_manager_app.h"
 #include "mojo/views/native_widget_view_manager.h"
@@ -50,7 +51,7 @@
     bounds.Inset(kFrameSize,
                  close_button_->bounds().bottom() + kButtonFrameMargin,
                  kFrameSize, kFrameSize);
-    controller_->app_view_->SetBounds(bounds);
+    controller_->app_view_->SetBounds(*mojo::Rect::From(bounds));
   }
   virtual gfx::Size GetPreferredSize(const views::View* host) const override {
     return gfx::Size();
@@ -120,7 +121,8 @@
       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
   params.native_widget =
       new mojo::NativeWidgetViewManager(widget_, shell, view_);
-  params.bounds = gfx::Rect(view_->bounds().size());
+  params.bounds = gfx::Rect(
+      0, 0, view_->bounds().width, view_->bounds().height);
   widget_->Init(params);
   widget_->SetContentsView(frame_view_);
   widget_->Show();
@@ -135,12 +137,12 @@
 
 void FrameController::ToggleMaximize() {
   if (!maximized_)
-    restored_bounds_ = view_->bounds();
+    restored_bounds_ = view_->bounds().To<gfx::Rect>();
   maximized_ = !maximized_;
   if (maximized_)
     view_->SetBounds(view_->parent()->bounds());
   else
-    view_->SetBounds(restored_bounds_);
+    view_->SetBounds(*mojo::Rect::From(restored_bounds_));
 }
 
 void FrameController::ActivateWindow() {
diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc
index 92eee59..ba20e35 100644
--- a/mojo/examples/wm_flow/wm/wm.cc
+++ b/mojo/examples/wm_flow/wm/wm.cc
@@ -176,7 +176,11 @@
 
   mojo::View* CreateTopLevelWindow(mojo::View** app_view) {
     mojo::View* frame_view = mojo::View::Create(view_manager_);
-    frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
+    mojo::Rect rect;
+    rect.x = next_window_origin_.x();
+    rect.y = next_window_origin_.y();
+    rect.width = rect.height = 400;
+    frame_view->SetBounds(rect);
     next_window_origin_.Offset(50, 50);
 
     aura::client::ActivationClient* client = aura::client::GetActivationClient(
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
index f6bea2c..25b39b3 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
@@ -19,6 +19,11 @@
     return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u);
   }
 
+  template <typename U>
+  U To() const {
+    return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this);
+  }
+
   {{struct.name}}();
   ~{{struct.name}}();
 
diff --git a/mojo/services/public/cpp/view_manager/BUILD.gn b/mojo/services/public/cpp/view_manager/BUILD.gn
index 1b38771..55fc3f8 100644
--- a/mojo/services/public/cpp/view_manager/BUILD.gn
+++ b/mojo/services/public/cpp/view_manager/BUILD.gn
@@ -27,8 +27,6 @@
   ]
   deps = [
     "//base",
-    "//mojo/converters/geometry",
-    "//mojo/converters/surfaces",
     "//mojo/public/c/gles2",
     "//mojo/public/cpp/bindings:bindings",
     "//mojo/public/interfaces/application",
@@ -38,7 +36,6 @@
     "//mojo/services/public/interfaces/view_manager",
     "//mojo/services/public/interfaces/window_manager",
     "//mojo/services/public/interfaces/window_manager2",
-    "//ui/gfx/geometry",
   ]
 }
 
diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc
index d0c86e0..d7d1013 100644
--- a/mojo/services/public/cpp/view_manager/lib/view.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view.cc
@@ -144,8 +144,8 @@
 class ScopedSetBoundsNotifier {
  public:
   ScopedSetBoundsNotifier(View* view,
-                          const gfx::Rect& old_bounds,
-                          const gfx::Rect& new_bounds)
+                          const Rect& old_bounds,
+                          const Rect& new_bounds)
       : view_(view),
         old_bounds_(old_bounds),
         new_bounds_(new_bounds) {
@@ -161,8 +161,8 @@
 
  private:
   View* view_;
-  const gfx::Rect old_bounds_;
-  const gfx::Rect new_bounds_;
+  const Rect old_bounds_;
+  const Rect new_bounds_;
 
   DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier);
 };
@@ -205,7 +205,7 @@
   LocalDestroy();
 }
 
-void View::SetBounds(const gfx::Rect& bounds) {
+void View::SetBounds(const Rect& bounds) {
   if (!OwnsView(manager_, this))
     return;
 
@@ -391,9 +391,12 @@
   return ReorderImpl(&parent_->children_, this, relative, direction);
 }
 
-void View::LocalSetBounds(const gfx::Rect& old_bounds,
-                          const gfx::Rect& new_bounds) {
-  DCHECK(old_bounds == bounds_);
+void View::LocalSetBounds(const Rect& old_bounds,
+                          const Rect& new_bounds) {
+  DCHECK(old_bounds.x == bounds_.x);
+  DCHECK(old_bounds.y == bounds_.y);
+  DCHECK(old_bounds.width == bounds_.width);
+  DCHECK(old_bounds.height == bounds_.height);
   ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds);
   bounds_ = new_bounds;
 }
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
index 8004d29..b7397b1 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
@@ -37,7 +37,7 @@
   private_view.set_visible(view_data->visible);
   private_view.set_drawn(view_data->drawn);
   client->AddView(view);
-  private_view.LocalSetBounds(gfx::Rect(), view_data->bounds.To<gfx::Rect>());
+  private_view.LocalSetBounds(Rect(), *view_data->bounds);
   if (parent)
     ViewPrivate(parent).LocalAddChild(view);
   return view;
@@ -154,10 +154,9 @@
   return HiWord(id) == connection_id_;
 }
 
-void ViewManagerClientImpl::SetBounds(Id view_id, const gfx::Rect& bounds) {
+void ViewManagerClientImpl::SetBounds(Id view_id, const Rect& bounds) {
   DCHECK(connected_);
-  service_->SetViewBounds(view_id, Rect::From(bounds),
-                          ActionCompletedCallback());
+  service_->SetViewBounds(view_id, bounds.Clone(), ActionCompletedCallback());
 }
 
 void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) {
@@ -265,8 +264,7 @@
                                                 RectPtr old_bounds,
                                                 RectPtr new_bounds) {
   View* view = GetViewById(view_id);
-  ViewPrivate(view).LocalSetBounds(old_bounds.To<gfx::Rect>(),
-                                   new_bounds.To<gfx::Rect>());
+  ViewPrivate(view).LocalSetBounds(*old_bounds, *new_bounds);
 }
 
 void ViewManagerClientImpl::OnViewHierarchyChanged(
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
index c9a4af4..3ec5e39 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
@@ -9,7 +9,6 @@
 #include "base/callback.h"
 #include "base/memory/scoped_vector.h"
 #include "base/memory/weak_ptr.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
 #include "mojo/services/public/cpp/view_manager/types.h"
 #include "mojo/services/public/cpp/view_manager/view.h"
 #include "mojo/services/public/cpp/view_manager/view_manager.h"
@@ -49,7 +48,7 @@
   // Returns true if the specified view was created by this connection.
   bool OwnsView(Id id) const;
 
-  void SetBounds(Id view_id, const gfx::Rect& bounds);
+  void SetBounds(Id view_id, const Rect& bounds);
   void SetSurfaceId(Id view_id, SurfaceIdPtr surface_id);
   void SetFocus(Id view_id);
   void SetVisible(Id view_id, bool visible);
diff --git a/mojo/services/public/cpp/view_manager/lib/view_private.h b/mojo/services/public/cpp/view_manager/lib/view_private.h
index 73138e2..c4f7073 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_private.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_private.h
@@ -48,8 +48,8 @@
   void LocalReorder(View* relative, OrderDirection direction) {
     view_->LocalReorder(relative, direction);
   }
-  void LocalSetBounds(const gfx::Rect& old_bounds,
-                      const gfx::Rect& new_bounds) {
+  void LocalSetBounds(const Rect& old_bounds,
+                      const Rect& new_bounds) {
     view_->LocalSetBounds(old_bounds, new_bounds);
   }
   void LocalSetDrawn(bool drawn) { view_->LocalSetDrawn(drawn); }
diff --git a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
index eafc3b9..83a1ce0 100644
--- a/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
+++ b/mojo/services/public/cpp/view_manager/tests/view_manager_unittest.cc
@@ -23,6 +23,18 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace mojo {
+
+// TODO(jam): move these somewhere else so they can be shared?
+
+inline bool operator==(const Rect& lhs, const Rect& rhs) {
+  return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width &&
+         lhs.height == lhs.height;
+}
+
+inline bool operator!=(const Rect& lhs, const Rect& rhs) {
+  return !(lhs == rhs);
+}
+
 namespace {
 
 const char kWindowManagerURL[] = "mojo:window_manager";
@@ -102,8 +114,8 @@
  private:
   // Overridden from ViewObserver:
   void OnViewBoundsChanged(View* view,
-                           const gfx::Rect& old_bounds,
-                           const gfx::Rect& new_bounds) override {
+                           const Rect& old_bounds,
+                           const Rect& new_bounds) override {
     DCHECK_EQ(view, view_);
     QuitRunLoop();
   }
@@ -410,7 +422,9 @@
   View* view_in_embedded = embedded->GetViewById(view->id());
   EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
 
-  view->SetBounds(gfx::Rect(100, 100));
+  Rect rect;
+  rect.width = rect.height = 100;
+  view->SetBounds(rect);
   EXPECT_NE(view->bounds(), view_in_embedded->bounds());
   WaitForBoundsToChange(view_in_embedded);
   EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
@@ -424,10 +438,15 @@
   ViewManager* embedded = Embed(window_manager(), view);
 
   View* view_in_embedded = embedded->GetViewById(view->id());
-  view->SetBounds(gfx::Rect(800, 600));
+  Rect rect;
+  rect.width = 800;
+  rect.height = 600;
+  view->SetBounds(rect);
   WaitForBoundsToChange(view_in_embedded);
 
-  view_in_embedded->SetBounds(gfx::Rect(1024, 768));
+  rect.width = 1024;
+  rect.height = 768;
+  view_in_embedded->SetBounds(rect);
   // Bounds change should have been rejected.
   EXPECT_EQ(view->bounds(), view_in_embedded->bounds());
 }
diff --git a/mojo/services/public/cpp/view_manager/tests/view_unittest.cc b/mojo/services/public/cpp/view_manager/tests/view_unittest.cc
index 2fb5bfc..87ed167 100644
--- a/mojo/services/public/cpp/view_manager/tests/view_unittest.cc
+++ b/mojo/services/public/cpp/view_manager/tests/view_unittest.cc
@@ -486,9 +486,9 @@
       base::StringPrintf("%d,%d", HiWord(id), LoWord(id));
 }
 
-std::string RectToString(const gfx::Rect& rect) {
+std::string RectToString(const Rect& rect) {
   return base::StringPrintf("%d,%d %dx%d",
-                            rect.x(), rect.y(), rect.width(), rect.height());
+                            rect.x, rect.y, rect.width, rect.height);
 }
 
 class BoundsChangeObserver : public ViewObserver {
@@ -507,8 +507,8 @@
  private:
   // Overridden from ViewObserver:
   void OnViewBoundsChanging(View* view,
-                            const gfx::Rect& old_bounds,
-                            const gfx::Rect& new_bounds) override {
+                            const Rect& old_bounds,
+                            const Rect& new_bounds) override {
     changes_.push_back(
         base::StringPrintf(
             "view=%s old_bounds=%s new_bounds=%s phase=changing",
@@ -517,8 +517,8 @@
             RectToString(new_bounds).c_str()));
   }
   void OnViewBoundsChanged(View* view,
-                           const gfx::Rect& old_bounds,
-                           const gfx::Rect& new_bounds) override {
+                           const Rect& old_bounds,
+                           const Rect& new_bounds) override {
     changes_.push_back(
         base::StringPrintf(
             "view=%s old_bounds=%s new_bounds=%s phase=changed",
@@ -539,7 +539,9 @@
   TestView v1;
   {
     BoundsChangeObserver observer(&v1);
-    v1.SetBounds(gfx::Rect(0, 0, 100, 100));
+    Rect rect;
+    rect.width = rect.height = 100;
+    v1.SetBounds(rect);
 
     Changes changes = observer.GetAndClearChanges();
     ASSERT_EQ(2U, changes.size());
diff --git a/mojo/services/public/cpp/view_manager/view.h b/mojo/services/public/cpp/view_manager/view.h
index a7161ea..405018a 100644
--- a/mojo/services/public/cpp/view_manager/view.h
+++ b/mojo/services/public/cpp/view_manager/view.h
@@ -12,9 +12,9 @@
 #include "mojo/public/cpp/bindings/array.h"
 #include "mojo/public/interfaces/application/service_provider.mojom.h"
 #include "mojo/services/public/cpp/view_manager/types.h"
+#include "mojo/services/public/interfaces/geometry/geometry.mojom.h"
 #include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
 #include "mojo/services/public/interfaces/view_manager/view_manager_constants.mojom.h"
-#include "ui/gfx/geometry/rect.h"
 
 namespace mojo {
 
@@ -42,8 +42,8 @@
   Id id() const { return id_; }
 
   // Geometric disposition.
-  const gfx::Rect& bounds() const { return bounds_; }
-  void SetBounds(const gfx::Rect& bounds);
+  const Rect& bounds() const { return bounds_; }
+  void SetBounds(const Rect& bounds);
 
   // Visibility (also see IsDrawn()).
   bool visible() const { return visible_; }
@@ -100,7 +100,7 @@
   void LocalRemoveChild(View* child);
   // Returns true if the order actually changed.
   bool LocalReorder(View* relative, OrderDirection direction);
-  void LocalSetBounds(const gfx::Rect& old_bounds, const gfx::Rect& new_bounds);
+  void LocalSetBounds(const Rect& old_bounds, const Rect& new_bounds);
   void LocalSetDrawn(bool drawn);
 
   ViewManager* manager_;
@@ -110,7 +110,7 @@
 
   ObserverList<ViewObserver> observers_;
 
-  gfx::Rect bounds_;
+  Rect bounds_;
 
   bool visible_;
 
diff --git a/mojo/services/public/cpp/view_manager/view_observer.h b/mojo/services/public/cpp/view_manager/view_observer.h
index 1a2ab7e..ab52666 100644
--- a/mojo/services/public/cpp/view_manager/view_observer.h
+++ b/mojo/services/public/cpp/view_manager/view_observer.h
@@ -12,10 +12,6 @@
 #include "mojo/services/public/cpp/view_manager/view.h"
 #include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
 
-namespace gfx {
-class Rect;
-}
-
 namespace mojo {
 
 class View;
@@ -54,11 +50,11 @@
   virtual void OnViewDestroyed(View* view) {}
 
   virtual void OnViewBoundsChanging(View* view,
-                                    const gfx::Rect& old_bounds,
-                                    const gfx::Rect& new_bounds) {}
+                                    const Rect& old_bounds,
+                                    const Rect& new_bounds) {}
   virtual void OnViewBoundsChanged(View* view,
-                                   const gfx::Rect& old_bounds,
-                                   const gfx::Rect& new_bounds) {}
+                                   const Rect& old_bounds,
+                                   const Rect& new_bounds) {}
 
   virtual void OnViewFocusChanged(View* gained_focus, View* lost_focus) {}
 
diff --git a/mojo/services/window_manager/DEPS b/mojo/services/window_manager/DEPS
index bbaa409..3ed4172 100644
--- a/mojo/services/window_manager/DEPS
+++ b/mojo/services/window_manager/DEPS
@@ -2,6 +2,7 @@
   "+mojo/aura",
   "+mojo/application",
   "+mojo/application_manager",
+  "+mojo/converters/geometry",
   "+mojo/converters/input_events",
   "+mojo/services/native_viewport",
   "+mojo/services/public",
diff --git a/mojo/services/window_manager/window_manager_app.cc b/mojo/services/window_manager/window_manager_app.cc
index 4f4545f..e9e7747 100644
--- a/mojo/services/window_manager/window_manager_app.cc
+++ b/mojo/services/window_manager/window_manager_app.cc
@@ -7,6 +7,7 @@
 #include "base/message_loop/message_loop.h"
 #include "base/stl_util.h"
 #include "mojo/aura/aura_init.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
 #include "mojo/converters/input_events/input_events_type_converters.h"
 #include "mojo/public/cpp/application/application_connection.h"
 #include "mojo/public/cpp/application/application_impl.h"
@@ -199,7 +200,7 @@
   root_ = root;
 
   window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_));
-  window_tree_host_->window()->SetBounds(root->bounds());
+  window_tree_host_->window()->SetBounds(root->bounds().To<gfx::Rect>());
   window_tree_host_->window()->Show();
 
   RegisterSubtree(root_, window_tree_host_->window());
@@ -272,10 +273,10 @@
 }
 
 void WindowManagerApp::OnViewBoundsChanged(View* view,
-                                           const gfx::Rect& old_bounds,
-                                           const gfx::Rect& new_bounds) {
+                                           const Rect& old_bounds,
+                                           const Rect& new_bounds) {
   aura::Window* window = GetWindowForViewId(view->id());
-  window->SetBounds(new_bounds);
+  window->SetBounds(new_bounds.To<gfx::Rect>());
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -336,7 +337,7 @@
   if (view == root_)
     window->AddPreTargetHandler(this);
   parent->AddChild(window);
-  window->SetBounds(view->bounds());
+  window->SetBounds(view->bounds().To<gfx::Rect>());
   window->Show();
   view_id_to_window_map_[view->id()] = window;
   View::Children::const_iterator it = view->children().begin();
diff --git a/mojo/services/window_manager/window_manager_app.h b/mojo/services/window_manager/window_manager_app.h
index 503c006..e2033a5 100644
--- a/mojo/services/window_manager/window_manager_app.h
+++ b/mojo/services/window_manager/window_manager_app.h
@@ -119,8 +119,8 @@
   void OnTreeChanged(const ViewObserver::TreeChangeParams& params) override;
   void OnViewDestroying(View* view) override;
   void OnViewBoundsChanged(View* view,
-                           const gfx::Rect& old_bounds,
-                           const gfx::Rect& new_bounds) override;
+                           const Rect& old_bounds,
+                           const Rect& new_bounds) override;
 
   // Overridden from ui::EventHandler:
   void OnEvent(ui::Event* event) override;
diff --git a/mojo/views/native_widget_view_manager.cc b/mojo/views/native_widget_view_manager.cc
index a9bd40b..41d85a7 100644
--- a/mojo/views/native_widget_view_manager.cc
+++ b/mojo/views/native_widget_view_manager.cc
@@ -5,6 +5,7 @@
 #include "mojo/views/native_widget_view_manager.h"
 
 #include "mojo/aura/window_tree_host_mojo.h"
+#include "mojo/converters/geometry/geometry_type_converters.h"
 #include "mojo/converters/input_events/input_events_type_converters.h"
 #include "ui/aura/client/aura_constants.h"
 #include "ui/aura/client/default_capture_client.h"
@@ -139,9 +140,10 @@
 }
 
 void NativeWidgetViewManager::OnViewBoundsChanged(View* view,
-                                                  const gfx::Rect& old_bounds,
-                                                  const gfx::Rect& new_bounds) {
-  GetWidget()->SetBounds(gfx::Rect(view->bounds().size()));
+                                                  const Rect& old_bounds,
+                                                  const Rect& new_bounds) {
+  gfx::Rect view_rect = view->bounds().To<gfx::Rect>();
+  GetWidget()->SetBounds(gfx::Rect(view_rect.size()));
 }
 
 void NativeWidgetViewManager::OnViewInputEvent(View* view,
diff --git a/mojo/views/native_widget_view_manager.h b/mojo/views/native_widget_view_manager.h
index 499a766..0c84a1d 100644
--- a/mojo/views/native_widget_view_manager.h
+++ b/mojo/views/native_widget_view_manager.h
@@ -45,8 +45,8 @@
   // ViewObserver:
   virtual void OnViewDestroyed(View* view) override;
   virtual void OnViewBoundsChanged(View* view,
-                                   const gfx::Rect& old_bounds,
-                                   const gfx::Rect& new_bounds) override;
+                                   const Rect& old_bounds,
+                                   const Rect& new_bounds) override;
   virtual void OnViewInputEvent(View* view, const EventPtr& event) override;
 
   scoped_ptr<WindowTreeHostMojo> window_tree_host_;