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

Side by Side Diff: ui/views/controls/native/native_view_host_aura.cc

Issue 397293005: Fix positioning of children of NativeViewHostAura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/native/native_view_host_aura.h" 5 #include "ui/views/controls/native/native_view_host_aura.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/aura/client/aura_constants.h" 8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/client/focus_client.h" 9 #include "ui/aura/client/focus_client.h"
10 #include "ui/aura/layout_manager.h"
10 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
11 #include "ui/base/cursor/cursor.h" 12 #include "ui/base/cursor/cursor.h"
12 #include "ui/views/controls/native/native_view_host.h" 13 #include "ui/views/controls/native/native_view_host.h"
13 #include "ui/views/view_constants_aura.h" 14 #include "ui/views/view_constants_aura.h"
14 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
15 16
16 namespace views { 17 namespace views {
17 18
19 namespace {
20
21 // This layout manager positions children relative to their grandparent's
22 // coordinate system.
23 class OffsettingLayoutManager : public aura::LayoutManager {
sky 2014/07/17 21:46:03 Seems heavyweight to create this rather than conve
Evan Stade 2014/07/17 22:50:35 yes, but converting on 136 doesn't work for the au
24 public:
25 OffsettingLayoutManager() {}
26 virtual ~OffsettingLayoutManager() {}
27
28 virtual void OnWindowResized() OVERRIDE {}
29 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {}
30 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
31 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
32 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
33 bool visible) OVERRIDE {}
34 virtual void SetChildBounds(aura::Window* child,
35 const gfx::Rect& requested_bounds) OVERRIDE {
36 gfx::Point origin = requested_bounds.origin();
37 gfx::Point this_origin = child->parent()->GetTargetBounds().origin();
38 origin.Offset(-this_origin.x(), -this_origin.y());
39 SetChildBoundsDirect(child, gfx::Rect(origin, requested_bounds.size()));
40 }
41 };
42
43 } // namespace
44
18 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) 45 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host)
19 : host_(host), 46 : host_(host),
20 clipping_window_(NULL) { 47 clipping_window_(NULL) {
21 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); 48 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN);
49 clipping_window_.SetLayoutManager(new OffsettingLayoutManager());
22 clipping_window_.set_owned_by_parent(false); 50 clipping_window_.set_owned_by_parent(false);
23 clipping_window_.SetName("NativeViewHostAuraClip"); 51 clipping_window_.SetName("NativeViewHostAuraClip");
24 clipping_window_.layer()->SetMasksToBounds(true); 52 clipping_window_.layer()->SetMasksToBounds(true);
25 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_)); 53 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_));
26 } 54 }
27 55
28 NativeViewHostAura::~NativeViewHostAura() { 56 NativeViewHostAura::~NativeViewHostAura() {
29 if (host_->native_view()) { 57 if (host_->native_view()) {
30 host_->native_view()->RemoveObserver(this); 58 host_->native_view()->RemoveObserver(this);
31 host_->native_view()->ClearProperty(views::kHostViewKey); 59 host_->native_view()->ClearProperty(views::kHostViewKey);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (host_->fast_resize()) { 126 if (host_->fast_resize()) {
99 gfx::Point origin(x, y); 127 gfx::Point origin(x, y);
100 views::View::ConvertPointFromWidget(host_, &origin); 128 views::View::ConvertPointFromWidget(host_, &origin);
101 InstallClip(origin.x(), origin.y(), w, h); 129 InstallClip(origin.x(), origin.y(), w, h);
102 width = host_->native_view()->bounds().width(); 130 width = host_->native_view()->bounds().width();
103 height = host_->native_view()->bounds().height(); 131 height = host_->native_view()->bounds().height();
104 } 132 }
105 clipping_window_.SetBounds(clip_rect_ ? *clip_rect_ 133 clipping_window_.SetBounds(clip_rect_ ? *clip_rect_
106 : gfx::Rect(x, y, w, h)); 134 : gfx::Rect(x, y, w, h));
107 135
108 gfx::Point clip_offset = clipping_window_.bounds().origin(); 136 host_->native_view()->SetBounds(gfx::Rect(x, y, width, height));
109 host_->native_view()->SetBounds(
110 gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), width, height));
111 host_->native_view()->Show(); 137 host_->native_view()->Show();
112 } 138 }
113 139
114 void NativeViewHostAura::HideWidget() { 140 void NativeViewHostAura::HideWidget() {
115 host_->native_view()->Hide(); 141 host_->native_view()->Hide();
116 } 142 }
117 143
118 void NativeViewHostAura::SetFocus() { 144 void NativeViewHostAura::SetFocus() {
119 aura::Window* window = host_->native_view(); 145 aura::Window* window = host_->native_view();
120 aura::client::FocusClient* client = aura::client::GetFocusClient(window); 146 aura::client::FocusClient* client = aura::client::GetFocusClient(window);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } else { 199 } else {
174 clipping_window_.RemoveChild(host_->native_view()); 200 clipping_window_.RemoveChild(host_->native_view());
175 } 201 }
176 host_->native_view()->SetBounds(clipping_window_.bounds()); 202 host_->native_view()->SetBounds(clipping_window_.bounds());
177 } 203 }
178 if (clipping_window_.parent()) 204 if (clipping_window_.parent())
179 clipping_window_.parent()->RemoveChild(&clipping_window_); 205 clipping_window_.parent()->RemoveChild(&clipping_window_);
180 } 206 }
181 207
182 } // namespace views 208 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698