OLD | NEW |
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/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "ui/aura/client/capture_client.h" | 16 #include "ui/aura/client/capture_client.h" |
17 #include "ui/aura/client/cursor_client.h" | 17 #include "ui/aura/client/cursor_client.h" |
18 #include "ui/aura/client/event_client.h" | 18 #include "ui/aura/client/event_client.h" |
19 #include "ui/aura/client/focus_client.h" | 19 #include "ui/aura/client/focus_client.h" |
20 #include "ui/aura/client/screen_position_client.h" | 20 #include "ui/aura/client/screen_position_client.h" |
21 #include "ui/aura/client/visibility_client.h" | 21 #include "ui/aura/client/visibility_client.h" |
22 #include "ui/aura/client/window_stacking_client.h" | 22 #include "ui/aura/client/window_stacking_client.h" |
23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
24 #include "ui/aura/layout_manager.h" | 24 #include "ui/aura/layout_manager.h" |
25 #include "ui/aura/window_delegate.h" | 25 #include "ui/aura/window_delegate.h" |
26 #include "ui/aura/window_event_dispatcher.h" | 26 #include "ui/aura/window_event_dispatcher.h" |
27 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
28 #include "ui/aura/window_tracker.h" | 28 #include "ui/aura/window_tracker.h" |
29 #include "ui/aura/window_tree_host.h" | 29 #include "ui/aura/window_tree_host.h" |
| 30 #include "ui/compositor/clone_layer.h" |
30 #include "ui/compositor/compositor.h" | 31 #include "ui/compositor/compositor.h" |
31 #include "ui/compositor/layer.h" | 32 #include "ui/compositor/layer.h" |
32 #include "ui/events/event_target_iterator.h" | 33 #include "ui/events/event_target_iterator.h" |
33 #include "ui/gfx/animation/multi_animation.h" | 34 #include "ui/gfx/animation/multi_animation.h" |
34 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/path.h" | 36 #include "ui/gfx/path.h" |
36 #include "ui/gfx/scoped_canvas.h" | 37 #include "ui/gfx/scoped_canvas.h" |
37 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
38 | 39 |
39 namespace aura { | 40 namespace aura { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 SetLayer(new ui::Layer(WindowLayerTypeToUILayerType(window_layer_type))); | 271 SetLayer(new ui::Layer(WindowLayerTypeToUILayerType(window_layer_type))); |
271 layer()->SetVisible(false); | 272 layer()->SetVisible(false); |
272 layer()->set_delegate(this); | 273 layer()->set_delegate(this); |
273 UpdateLayerName(name_); | 274 UpdateLayerName(name_); |
274 layer()->SetFillsBoundsOpaquely(!transparent_); | 275 layer()->SetFillsBoundsOpaquely(!transparent_); |
275 } | 276 } |
276 | 277 |
277 Env::GetInstance()->NotifyWindowInitialized(this); | 278 Env::GetInstance()->NotifyWindowInitialized(this); |
278 } | 279 } |
279 | 280 |
280 // TODO(sky): move to match new position. | |
281 scoped_ptr<ui::Layer> Window::RecreateLayer() { | |
282 // Disconnect the old layer, but don't delete it. | |
283 scoped_ptr<ui::Layer> old_layer(AcquireLayer()); | |
284 if (!old_layer) | |
285 return old_layer.Pass(); | |
286 | |
287 old_layer->set_delegate(NULL); | |
288 | |
289 const gfx::Rect layer_bounds(old_layer->bounds()); | |
290 SetLayer(new ui::Layer(old_layer->type())); | |
291 layer()->SetVisible(old_layer->visible()); | |
292 layer()->set_scale_content(old_layer->scale_content()); | |
293 layer()->SetBounds(layer_bounds); | |
294 layer()->set_delegate(this); | |
295 layer()->SetMasksToBounds(old_layer->GetMasksToBounds()); | |
296 | |
297 if (delegate_) | |
298 delegate_->DidRecreateLayer(old_layer.get(), layer()); | |
299 | |
300 UpdateLayerName(name_); | |
301 layer()->SetFillsBoundsOpaquely(!transparent_); | |
302 // Install new layer as a sibling of the old layer, stacked below it. | |
303 if (old_layer->parent()) { | |
304 old_layer->parent()->Add(layer()); | |
305 old_layer->parent()->StackBelow(layer(), old_layer.get()); | |
306 } | |
307 // Migrate all the child layers over to the new layer. Copy the list because | |
308 // the items are removed during iteration. | |
309 std::vector<ui::Layer*> children_copy = old_layer->children(); | |
310 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin(); | |
311 it != children_copy.end(); | |
312 ++it) { | |
313 ui::Layer* child = *it; | |
314 layer()->Add(child); | |
315 } | |
316 return old_layer.Pass(); | |
317 } | |
318 | |
319 void Window::SetType(ui::wm::WindowType type) { | 281 void Window::SetType(ui::wm::WindowType type) { |
320 // Cannot change type after the window is initialized. | 282 // Cannot change type after the window is initialized. |
321 DCHECK(!layer()); | 283 DCHECK(!layer()); |
322 type_ = type; | 284 type_ = type; |
323 } | 285 } |
324 | 286 |
325 void Window::SetName(const std::string& name) { | 287 void Window::SetName(const std::string& name) { |
326 name_ = name; | 288 name_ = name; |
327 | 289 |
328 if (layer()) | 290 if (layer()) |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 } | 746 } |
785 | 747 |
786 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { | 748 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { |
787 ScopedCursorHider hider(this); | 749 ScopedCursorHider hider(this); |
788 if (IsRootWindow()) | 750 if (IsRootWindow()) |
789 host_->OnDeviceScaleFactorChanged(device_scale_factor); | 751 host_->OnDeviceScaleFactorChanged(device_scale_factor); |
790 if (delegate_) | 752 if (delegate_) |
791 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); | 753 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); |
792 } | 754 } |
793 | 755 |
| 756 scoped_ptr<ui::Layer> Window::RecreateLayer() { |
| 757 scoped_ptr<ui::Layer> old_layer(ui::CloneLayer(this)); |
| 758 if (!old_layer) |
| 759 return old_layer.Pass(); |
| 760 |
| 761 if (delegate_) |
| 762 delegate_->DidRecreateLayer(old_layer.get(), layer()); |
| 763 |
| 764 return old_layer.Pass(); |
| 765 } |
| 766 |
794 #if !defined(NDEBUG) | 767 #if !defined(NDEBUG) |
795 std::string Window::GetDebugInfo() const { | 768 std::string Window::GetDebugInfo() const { |
796 return base::StringPrintf( | 769 return base::StringPrintf( |
797 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f", | 770 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f", |
798 name().empty() ? "Unknown" : name().c_str(), id(), | 771 name().empty() ? "Unknown" : name().c_str(), id(), |
799 bounds().x(), bounds().y(), bounds().width(), bounds().height(), | 772 bounds().x(), bounds().y(), bounds().width(), bounds().height(), |
800 visible_ ? "WindowVisible" : "WindowHidden", | 773 visible_ ? "WindowVisible" : "WindowHidden", |
801 layer() ? | 774 layer() ? |
802 (layer()->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") : | 775 (layer()->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") : |
803 "NoLayer", | 776 "NoLayer", |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 return window; | 1418 return window; |
1446 if (offset) | 1419 if (offset) |
1447 *offset += window->bounds().OffsetFromOrigin(); | 1420 *offset += window->bounds().OffsetFromOrigin(); |
1448 } | 1421 } |
1449 if (offset) | 1422 if (offset) |
1450 *offset = gfx::Vector2d(); | 1423 *offset = gfx::Vector2d(); |
1451 return NULL; | 1424 return NULL; |
1452 } | 1425 } |
1453 | 1426 |
1454 } // namespace aura | 1427 } // namespace aura |
OLD | NEW |