Android: Get rid of extra dup()s on launching child processes
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / desktop_screen_position_client.cc
blobcf49c96fca4547debb4a48bcab445233f9d60650
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h"
7 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
9 namespace views {
11 namespace {
13 // Returns true if bounds passed to window in SetBounds should be treated as
14 // though they are in screen coordinates.
15 bool PositionWindowInScreenCoordinates(aura::Window* window) {
16 if (window->type() == ui::wm::WINDOW_TYPE_POPUP)
17 return true;
19 Widget* widget = Widget::GetWidgetForNativeView(window);
20 return widget && widget->is_top_level();
23 } // namespace
25 DesktopScreenPositionClient::DesktopScreenPositionClient(
26 aura::Window* root_window)
27 : wm::DefaultScreenPositionClient(), root_window_(root_window) {
28 aura::client::SetScreenPositionClient(root_window_, this);
31 DesktopScreenPositionClient::~DesktopScreenPositionClient() {
32 aura::client::SetScreenPositionClient(root_window_, NULL);
35 void DesktopScreenPositionClient::SetBounds(aura::Window* window,
36 const gfx::Rect& bounds,
37 const gfx::Display& display) {
38 // TODO(jam): Use the 3rd parameter, |display|.
39 aura::Window* root = window->GetRootWindow();
41 // This method assumes that |window| does not have an associated
42 // DesktopNativeWidgetAura.
43 internal::NativeWidgetPrivate* desktop_native_widget =
44 DesktopNativeWidgetAura::ForWindow(root);
45 DCHECK(!desktop_native_widget ||
46 desktop_native_widget->GetNativeView() != window);
48 if (PositionWindowInScreenCoordinates(window)) {
49 // The caller expects windows we consider "embedded" to be placed in the
50 // screen coordinate system. So we need to offset the root window's
51 // position (which is in screen coordinates) from these bounds.
53 gfx::Point origin = bounds.origin();
54 aura::Window::ConvertPointToTarget(window->parent(), root, &origin);
56 gfx::Point host_origin = GetOriginInScreen(root);
57 origin.Offset(-host_origin.x(), -host_origin.y());
58 window->SetBounds(gfx::Rect(origin, bounds.size()));
59 return;
62 window->SetBounds(bounds);
65 } // namespace views