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

Side by Side Diff: ui/aura/window.cc

Issue 184983005: Remove Views dependency from window_animations.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 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 | « ui/aura/test/window_test_api.cc ('k') | ui/compositor/layer.h » ('j') | 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/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"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 user_data_(NULL), 210 user_data_(NULL),
211 ignore_events_(false), 211 ignore_events_(false),
212 // Don't notify newly added observers during notification. This causes 212 // Don't notify newly added observers during notification. This causes
213 // problems for code that adds an observer as part of an observer 213 // problems for code that adds an observer as part of an observer
214 // notification (such as the workspace code). 214 // notification (such as the workspace code).
215 observers_(ObserverList<WindowObserver>::NOTIFY_EXISTING_ONLY) { 215 observers_(ObserverList<WindowObserver>::NOTIFY_EXISTING_ONLY) {
216 set_target_handler(delegate_); 216 set_target_handler(delegate_);
217 } 217 }
218 218
219 Window::~Window() { 219 Window::~Window() {
220 // |layer_| can be NULL during tests, or if this Window is layerless. 220 // |layer()| can be NULL during tests, or if this Window is layerless.
221 if (layer_) 221 if (layer())
222 layer_->SuppressPaint(); 222 layer()->SuppressPaint();
223 223
224 // Let the delegate know we're in the processing of destroying. 224 // Let the delegate know we're in the processing of destroying.
225 if (delegate_) 225 if (delegate_)
226 delegate_->OnWindowDestroying(this); 226 delegate_->OnWindowDestroying(this);
227 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this)); 227 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this));
228 228
229 // Let the root know so that it can remove any references to us. 229 // Let the root know so that it can remove any references to us.
230 WindowTreeHost* host = GetHost(); 230 WindowTreeHost* host = GetHost();
231 if (host) 231 if (host)
232 host->dispatcher()->OnWindowDestroying(this); 232 host->dispatcher()->OnWindowDestroying(this);
(...skipping 20 matching lines...) Expand all
253 iter != prop_map_.end(); 253 iter != prop_map_.end();
254 ++iter) { 254 ++iter) {
255 if (iter->second.deallocator) 255 if (iter->second.deallocator)
256 (*iter->second.deallocator)(iter->second.value); 256 (*iter->second.deallocator)(iter->second.value);
257 } 257 }
258 prop_map_.clear(); 258 prop_map_.clear();
259 259
260 // If we have layer it will either be destroyed by |layer_owner_|'s dtor, or 260 // If we have layer it will either be destroyed by |layer_owner_|'s dtor, or
261 // by whoever acquired it. We don't have a layer if Init() wasn't invoked or 261 // by whoever acquired it. We don't have a layer if Init() wasn't invoked or
262 // we are layerless. 262 // we are layerless.
263 if (layer_) { 263 if (layer())
264 layer_->set_delegate(NULL); 264 layer()->set_delegate(NULL);
265 layer_ = NULL; 265 DestroyLayer();
266 }
267 } 266 }
268 267
269 void Window::Init(WindowLayerType window_layer_type) { 268 void Window::Init(WindowLayerType window_layer_type) {
270 if (window_layer_type != WINDOW_LAYER_NONE) { 269 if (window_layer_type != WINDOW_LAYER_NONE) {
271 layer_ = new ui::Layer(WindowLayerTypeToUILayerType(window_layer_type)); 270 SetLayer(new ui::Layer(WindowLayerTypeToUILayerType(window_layer_type)));
272 layer_owner_.reset(layer_); 271 layer()->SetVisible(false);
273 layer_->SetVisible(false); 272 layer()->set_delegate(this);
274 layer_->set_delegate(this);
275 UpdateLayerName(name_); 273 UpdateLayerName(name_);
276 layer_->SetFillsBoundsOpaquely(!transparent_); 274 layer()->SetFillsBoundsOpaquely(!transparent_);
277 } 275 }
278 276
279 Env::GetInstance()->NotifyWindowInitialized(this); 277 Env::GetInstance()->NotifyWindowInitialized(this);
280 } 278 }
281 279
282 ui::Layer* Window::RecreateLayer() { 280 ui::Layer* Window::RecreateLayer() {
283 // Disconnect the old layer, but don't delete it. 281 // Disconnect the old layer, but don't delete it.
284 ui::Layer* old_layer = AcquireLayer(); 282 ui::Layer* old_layer = AcquireLayer();
285 if (!old_layer) 283 if (!old_layer)
286 return NULL; 284 return NULL;
287 285
288 bounds_.SetRect(0, 0, 0, 0); 286 bounds_.SetRect(0, 0, 0, 0);
289 287
290 old_layer->set_delegate(NULL); 288 old_layer->set_delegate(NULL);
291 289
292 layer_ = new ui::Layer(old_layer->type()); 290 SetLayer(new ui::Layer(old_layer->type()));
293 layer_owner_.reset(layer_); 291 layer()->SetVisible(old_layer->visible());
294 layer_->SetVisible(old_layer->visible()); 292 layer()->set_scale_content(old_layer->scale_content());
295 layer_->set_scale_content(old_layer->scale_content()); 293 layer()->set_delegate(this);
296 layer_->set_delegate(this); 294 layer()->SetMasksToBounds(old_layer->GetMasksToBounds());
297 layer_->SetMasksToBounds(old_layer->GetMasksToBounds());
298 295
299 if (delegate_) 296 if (delegate_)
300 delegate_->DidRecreateLayer(old_layer, layer_); 297 delegate_->DidRecreateLayer(old_layer, layer());
301 298
302 UpdateLayerName(name_); 299 UpdateLayerName(name_);
303 layer_->SetFillsBoundsOpaquely(!transparent_); 300 layer()->SetFillsBoundsOpaquely(!transparent_);
304 // Install new layer as a sibling of the old layer, stacked below it. 301 // Install new layer as a sibling of the old layer, stacked below it.
305 if (old_layer->parent()) { 302 if (old_layer->parent()) {
306 old_layer->parent()->Add(layer_); 303 old_layer->parent()->Add(layer());
307 old_layer->parent()->StackBelow(layer_, old_layer); 304 old_layer->parent()->StackBelow(layer(), old_layer);
308 } 305 }
309 // Migrate all the child layers over to the new layer. Copy the list because 306 // Migrate all the child layers over to the new layer. Copy the list because
310 // the items are removed during iteration. 307 // the items are removed during iteration.
311 std::vector<ui::Layer*> children_copy = old_layer->children(); 308 std::vector<ui::Layer*> children_copy = old_layer->children();
312 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin(); 309 for (std::vector<ui::Layer*>::const_iterator it = children_copy.begin();
313 it != children_copy.end(); 310 it != children_copy.end();
314 ++it) { 311 ++it) {
315 ui::Layer* child = *it; 312 ui::Layer* child = *it;
316 layer_->Add(child); 313 layer()->Add(child);
317 } 314 }
318 return old_layer; 315 return old_layer;
319 } 316 }
320 317
321 void Window::SetType(ui::wm::WindowType type) { 318 void Window::SetType(ui::wm::WindowType type) {
322 // Cannot change type after the window is initialized. 319 // Cannot change type after the window is initialized.
323 DCHECK(!layer_); 320 DCHECK(!layer());
324 type_ = type; 321 type_ = type;
325 } 322 }
326 323
327 void Window::SetName(const std::string& name) { 324 void Window::SetName(const std::string& name) {
328 name_ = name; 325 name_ = name;
329 326
330 if (layer_) 327 if (layer())
331 UpdateLayerName(name_); 328 UpdateLayerName(name_);
332 } 329 }
333 330
334 void Window::SetTransparent(bool transparent) { 331 void Window::SetTransparent(bool transparent) {
335 transparent_ = transparent; 332 transparent_ = transparent;
336 if (layer_) 333 if (layer())
337 layer_->SetFillsBoundsOpaquely(!transparent_); 334 layer()->SetFillsBoundsOpaquely(!transparent_);
338 } 335 }
339 336
340 Window* Window::GetRootWindow() { 337 Window* Window::GetRootWindow() {
341 return const_cast<Window*>( 338 return const_cast<Window*>(
342 static_cast<const Window*>(this)->GetRootWindow()); 339 static_cast<const Window*>(this)->GetRootWindow());
343 } 340 }
344 341
345 const Window* Window::GetRootWindow() const { 342 const Window* Window::GetRootWindow() const {
346 return IsRootWindow() ? this : parent_ ? parent_->GetRootWindow() : NULL; 343 return IsRootWindow() ? this : parent_ ? parent_->GetRootWindow() : NULL;
347 } 344 }
(...skipping 18 matching lines...) Expand all
366 } 363 }
367 364
368 bool Window::IsVisible() const { 365 bool Window::IsVisible() const {
369 // Layer visibility can be inconsistent with window visibility, for example 366 // Layer visibility can be inconsistent with window visibility, for example
370 // when a Window is hidden, we want this function to return false immediately 367 // when a Window is hidden, we want this function to return false immediately
371 // after, even though the client may decide to animate the hide effect (and 368 // after, even though the client may decide to animate the hide effect (and
372 // so the layer will be visible for some time after Hide() is called). 369 // so the layer will be visible for some time after Hide() is called).
373 for (const Window* window = this; window; window = window->parent()) { 370 for (const Window* window = this; window; window = window->parent()) {
374 if (!window->visible_) 371 if (!window->visible_)
375 return false; 372 return false;
376 if (window->layer_) 373 if (window->layer())
377 return window->layer_->IsDrawn(); 374 return window->layer()->IsDrawn();
378 } 375 }
379 return false; 376 return false;
380 } 377 }
381 378
382 gfx::Rect Window::GetBoundsInRootWindow() const { 379 gfx::Rect Window::GetBoundsInRootWindow() const {
383 // TODO(beng): There may be a better way to handle this, and the existing code 380 // TODO(beng): There may be a better way to handle this, and the existing code
384 // is likely wrong anyway in a multi-display world, but this will 381 // is likely wrong anyway in a multi-display world, but this will
385 // do for now. 382 // do for now.
386 if (!GetRootWindow()) 383 if (!GetRootWindow())
387 return bounds(); 384 return bounds();
(...skipping 11 matching lines...) Expand all
399 if (screen_position_client) { 396 if (screen_position_client) {
400 gfx::Point origin = bounds.origin(); 397 gfx::Point origin = bounds.origin();
401 screen_position_client->ConvertPointToScreen(root, &origin); 398 screen_position_client->ConvertPointToScreen(root, &origin);
402 bounds.set_origin(origin); 399 bounds.set_origin(origin);
403 } 400 }
404 } 401 }
405 return bounds; 402 return bounds;
406 } 403 }
407 404
408 void Window::SetTransform(const gfx::Transform& transform) { 405 void Window::SetTransform(const gfx::Transform& transform) {
409 if (!layer_) { 406 if (!layer()) {
410 // Transforms aren't supported on layerless windows. 407 // Transforms aren't supported on layerless windows.
411 NOTREACHED(); 408 NOTREACHED();
412 return; 409 return;
413 } 410 }
414 WindowEventDispatcher* dispatcher = GetHost()->dispatcher(); 411 WindowEventDispatcher* dispatcher = GetHost()->dispatcher();
415 bool contained_mouse = IsVisible() && dispatcher && 412 bool contained_mouse = IsVisible() && dispatcher &&
416 ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot()); 413 ContainsPointInRoot(dispatcher->GetLastMouseLocationInRoot());
417 layer_->SetTransform(transform); 414 layer()->SetTransform(transform);
418 if (dispatcher) 415 if (dispatcher)
419 dispatcher->OnWindowTransformed(this, contained_mouse); 416 dispatcher->OnWindowTransformed(this, contained_mouse);
420 } 417 }
421 418
422 void Window::SetLayoutManager(LayoutManager* layout_manager) { 419 void Window::SetLayoutManager(LayoutManager* layout_manager) {
423 if (layout_manager == layout_manager_) 420 if (layout_manager == layout_manager_)
424 return; 421 return;
425 layout_manager_.reset(layout_manager); 422 layout_manager_.reset(layout_manager);
426 if (!layout_manager) 423 if (!layout_manager)
427 return; 424 return;
(...skipping 26 matching lines...) Expand all
454 gfx::Point origin = new_bounds_in_screen.origin(); 451 gfx::Point origin = new_bounds_in_screen.origin();
455 aura::client::ScreenPositionClient* screen_position_client = 452 aura::client::ScreenPositionClient* screen_position_client =
456 aura::client::GetScreenPositionClient(root); 453 aura::client::GetScreenPositionClient(root);
457 screen_position_client->SetBounds(this, new_bounds_in_screen, dst_display); 454 screen_position_client->SetBounds(this, new_bounds_in_screen, dst_display);
458 return; 455 return;
459 } 456 }
460 SetBounds(new_bounds_in_screen); 457 SetBounds(new_bounds_in_screen);
461 } 458 }
462 459
463 gfx::Rect Window::GetTargetBounds() const { 460 gfx::Rect Window::GetTargetBounds() const {
464 if (!layer_) 461 if (!layer())
465 return bounds(); 462 return bounds();
466 463
467 if (!parent_ || parent_->layer_) 464 if (!parent_ || parent_->layer())
468 return layer_->GetTargetBounds(); 465 return layer()->GetTargetBounds();
469 466
470 // We have a layer but our parent (who is valid) doesn't. This means the 467 // We have a layer but our parent (who is valid) doesn't. This means the
471 // coordinates of the layer are relative to the first ancestor with a layer; 468 // coordinates of the layer are relative to the first ancestor with a layer;
472 // convert to be relative to parent. 469 // convert to be relative to parent.
473 gfx::Vector2d offset; 470 gfx::Vector2d offset;
474 const aura::Window* ancestor_with_layer = 471 const aura::Window* ancestor_with_layer =
475 parent_->GetAncestorWithLayer(&offset); 472 parent_->GetAncestorWithLayer(&offset);
476 if (!ancestor_with_layer) 473 if (!ancestor_with_layer)
477 return layer_->GetTargetBounds(); 474 return layer()->GetTargetBounds();
478 475
479 gfx::Rect layer_target_bounds = layer_->GetTargetBounds(); 476 gfx::Rect layer_target_bounds = layer()->GetTargetBounds();
480 layer_target_bounds -= offset; 477 layer_target_bounds -= offset;
481 return layer_target_bounds; 478 return layer_target_bounds;
482 } 479 }
483 480
484 void Window::SchedulePaintInRect(const gfx::Rect& rect) { 481 void Window::SchedulePaintInRect(const gfx::Rect& rect) {
485 if (!layer_ && parent_) { 482 if (!layer() && parent_) {
486 // Notification of paint scheduled happens for the window with a layer. 483 // Notification of paint scheduled happens for the window with a layer.
487 gfx::Rect parent_rect(bounds().size()); 484 gfx::Rect parent_rect(bounds().size());
488 parent_rect.Intersect(rect); 485 parent_rect.Intersect(rect);
489 if (!parent_rect.IsEmpty()) { 486 if (!parent_rect.IsEmpty()) {
490 parent_rect.Offset(bounds().origin().OffsetFromOrigin()); 487 parent_rect.Offset(bounds().origin().OffsetFromOrigin());
491 parent_->SchedulePaintInRect(parent_rect); 488 parent_->SchedulePaintInRect(parent_rect);
492 } 489 }
493 } else if (layer_ && layer_->SchedulePaint(rect)) { 490 } else if (layer() && layer()->SchedulePaint(rect)) {
494 FOR_EACH_OBSERVER( 491 FOR_EACH_OBSERVER(
495 WindowObserver, observers_, OnWindowPaintScheduled(this, rect)); 492 WindowObserver, observers_, OnWindowPaintScheduled(this, rect));
496 } 493 }
497 } 494 }
498 495
499 void Window::StackChildAtTop(Window* child) { 496 void Window::StackChildAtTop(Window* child) {
500 if (children_.size() <= 1 || child == children_.back()) 497 if (children_.size() <= 1 || child == children_.back())
501 return; // In the front already. 498 return; // In the front already.
502 StackChildAbove(child, children_.back()); 499 StackChildAbove(child, children_.back());
503 } 500 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 if (!source) 598 if (!source)
602 return; 599 return;
603 if (source->GetRootWindow() != target->GetRootWindow()) { 600 if (source->GetRootWindow() != target->GetRootWindow()) {
604 client::ScreenPositionClient* source_client = 601 client::ScreenPositionClient* source_client =
605 client::GetScreenPositionClient(source->GetRootWindow()); 602 client::GetScreenPositionClient(source->GetRootWindow());
606 source_client->ConvertPointToScreen(source, point); 603 source_client->ConvertPointToScreen(source, point);
607 604
608 client::ScreenPositionClient* target_client = 605 client::ScreenPositionClient* target_client =
609 client::GetScreenPositionClient(target->GetRootWindow()); 606 client::GetScreenPositionClient(target->GetRootWindow());
610 target_client->ConvertPointFromScreen(target, point); 607 target_client->ConvertPointFromScreen(target, point);
611 } else if ((source != target) && (!source->layer_ || !target->layer_)) { 608 } else if ((source != target) && (!source->layer() || !target->layer())) {
612 if (!source->layer_) { 609 if (!source->layer()) {
613 gfx::Vector2d offset_to_layer; 610 gfx::Vector2d offset_to_layer;
614 source = source->GetAncestorWithLayer(&offset_to_layer); 611 source = source->GetAncestorWithLayer(&offset_to_layer);
615 *point += offset_to_layer; 612 *point += offset_to_layer;
616 } 613 }
617 if (!target->layer_) { 614 if (!target->layer()) {
618 gfx::Vector2d offset_to_layer; 615 gfx::Vector2d offset_to_layer;
619 target = target->GetAncestorWithLayer(&offset_to_layer); 616 target = target->GetAncestorWithLayer(&offset_to_layer);
620 *point -= offset_to_layer; 617 *point -= offset_to_layer;
621 } 618 }
622 ui::Layer::ConvertPointToLayer(source->layer_, target->layer_, point); 619 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
623 } else { 620 } else {
624 ui::Layer::ConvertPointToLayer(source->layer_, target->layer_, point); 621 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
625 } 622 }
626 } 623 }
627 624
628 void Window::MoveCursorTo(const gfx::Point& point_in_window) { 625 void Window::MoveCursorTo(const gfx::Point& point_in_window) {
629 Window* root_window = GetRootWindow(); 626 Window* root_window = GetRootWindow();
630 DCHECK(root_window); 627 DCHECK(root_window);
631 gfx::Point point_in_root(point_in_window); 628 gfx::Point point_in_root(point_in_window);
632 ConvertPointToTarget(this, root_window, &point_in_root); 629 ConvertPointToTarget(this, root_window, &point_in_root);
633 root_window->GetHost()->MoveCursorTo(point_in_root); 630 root_window->GetHost()->MoveCursorTo(point_in_root);
634 } 631 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 752
756 bool Window::HasCapture() { 753 bool Window::HasCapture() {
757 Window* root_window = GetRootWindow(); 754 Window* root_window = GetRootWindow();
758 if (!root_window) 755 if (!root_window)
759 return false; 756 return false;
760 client::CaptureClient* capture_client = client::GetCaptureClient(root_window); 757 client::CaptureClient* capture_client = client::GetCaptureClient(root_window);
761 return capture_client && capture_client->GetCaptureWindow() == this; 758 return capture_client && capture_client->GetCaptureWindow() == this;
762 } 759 }
763 760
764 void Window::SuppressPaint() { 761 void Window::SuppressPaint() {
765 if (layer_) 762 if (layer())
766 layer_->SuppressPaint(); 763 layer()->SuppressPaint();
767 } 764 }
768 765
769 // {Set,Get,Clear}Property are implemented in window_property.h. 766 // {Set,Get,Clear}Property are implemented in window_property.h.
770 767
771 void Window::SetNativeWindowProperty(const char* key, void* value) { 768 void Window::SetNativeWindowProperty(const char* key, void* value) {
772 SetPropertyInternal( 769 SetPropertyInternal(
773 key, key, NULL, reinterpret_cast<int64>(value), 0); 770 key, key, NULL, reinterpret_cast<int64>(value), 0);
774 } 771 }
775 772
776 void* Window::GetNativeWindowProperty(const char* key) const { 773 void* Window::GetNativeWindowProperty(const char* key) const {
777 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); 774 return reinterpret_cast<void*>(GetPropertyInternal(key, 0));
778 } 775 }
779 776
780 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { 777 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) {
781 ScopedCursorHider hider(this); 778 ScopedCursorHider hider(this);
782 if (IsRootWindow()) 779 if (IsRootWindow())
783 host_->OnDeviceScaleFactorChanged(device_scale_factor); 780 host_->OnDeviceScaleFactorChanged(device_scale_factor);
784 if (delegate_) 781 if (delegate_)
785 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); 782 delegate_->OnDeviceScaleFactorChanged(device_scale_factor);
786 } 783 }
787 784
788 #if !defined(NDEBUG) 785 #if !defined(NDEBUG)
789 std::string Window::GetDebugInfo() const { 786 std::string Window::GetDebugInfo() const {
790 return base::StringPrintf( 787 return base::StringPrintf(
791 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f", 788 "%s<%d> bounds(%d, %d, %d, %d) %s %s opacity=%.1f",
792 name().empty() ? "Unknown" : name().c_str(), id(), 789 name().empty() ? "Unknown" : name().c_str(), id(),
793 bounds().x(), bounds().y(), bounds().width(), bounds().height(), 790 bounds().x(), bounds().y(), bounds().width(), bounds().height(),
794 visible_ ? "WindowVisible" : "WindowHidden", 791 visible_ ? "WindowVisible" : "WindowHidden",
795 layer_ ? 792 layer() ?
796 (layer_->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") : 793 (layer()->GetTargetVisibility() ? "LayerVisible" : "LayerHidden") :
797 "NoLayer", 794 "NoLayer",
798 layer_ ? layer_->opacity() : 1.0f); 795 layer() ? layer()->opacity() : 1.0f);
799 } 796 }
800 797
801 void Window::PrintWindowHierarchy(int depth) const { 798 void Window::PrintWindowHierarchy(int depth) const {
802 VLOG(0) << base::StringPrintf( 799 VLOG(0) << base::StringPrintf(
803 "%*s%s", depth * 2, "", GetDebugInfo().c_str()); 800 "%*s%s", depth * 2, "", GetDebugInfo().c_str());
804 for (Windows::const_iterator it = children_.begin(); 801 for (Windows::const_iterator it = children_.begin();
805 it != children_.end(); ++it) { 802 it != children_.end(); ++it) {
806 Window* child = *it; 803 Window* child = *it;
807 child->PrintWindowHierarchy(depth + 1); 804 child->PrintWindowHierarchy(depth + 1);
808 } 805 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 actual_new_bounds.set_width( 879 actual_new_bounds.set_width(
883 std::max(min_size.width(), actual_new_bounds.width())); 880 std::max(min_size.width(), actual_new_bounds.width()));
884 actual_new_bounds.set_height( 881 actual_new_bounds.set_height(
885 std::max(min_size.height(), actual_new_bounds.height())); 882 std::max(min_size.height(), actual_new_bounds.height()));
886 } 883 }
887 884
888 gfx::Rect old_bounds = GetTargetBounds(); 885 gfx::Rect old_bounds = GetTargetBounds();
889 886
890 // Always need to set the layer's bounds -- even if it is to the same thing. 887 // Always need to set the layer's bounds -- even if it is to the same thing.
891 // This may cause important side effects such as stopping animation. 888 // This may cause important side effects such as stopping animation.
892 if (!layer_) { 889 if (!layer()) {
893 const gfx::Vector2d origin_delta = new_bounds.OffsetFromOrigin() - 890 const gfx::Vector2d origin_delta = new_bounds.OffsetFromOrigin() -
894 bounds_.OffsetFromOrigin(); 891 bounds_.OffsetFromOrigin();
895 bounds_ = new_bounds; 892 bounds_ = new_bounds;
896 OffsetLayerBounds(origin_delta); 893 OffsetLayerBounds(origin_delta);
897 } else { 894 } else {
898 if (parent_ && !parent_->layer_) { 895 if (parent_ && !parent_->layer()) {
899 gfx::Vector2d offset; 896 gfx::Vector2d offset;
900 const aura::Window* ancestor_with_layer = 897 const aura::Window* ancestor_with_layer =
901 parent_->GetAncestorWithLayer(&offset); 898 parent_->GetAncestorWithLayer(&offset);
902 if (ancestor_with_layer) 899 if (ancestor_with_layer)
903 actual_new_bounds.Offset(offset); 900 actual_new_bounds.Offset(offset);
904 } 901 }
905 layer_->SetBounds(actual_new_bounds); 902 layer()->SetBounds(actual_new_bounds);
906 } 903 }
907 904
908 // If we are currently not the layer's delegate, we will not get bounds 905 // If we are currently not the layer's delegate, we will not get bounds
909 // changed notification from the layer (this typically happens after animating 906 // changed notification from the layer (this typically happens after animating
910 // hidden). We must notify ourselves. 907 // hidden). We must notify ourselves.
911 if (!layer_ || layer_->delegate() != this) 908 if (!layer() || layer()->delegate() != this)
912 OnWindowBoundsChanged(old_bounds, ContainsMouse()); 909 OnWindowBoundsChanged(old_bounds, ContainsMouse());
913 } 910 }
914 911
915 void Window::SetVisible(bool visible) { 912 void Window::SetVisible(bool visible) {
916 if ((layer_ && visible == layer_->GetTargetVisibility()) || 913 if ((layer() && visible == layer()->GetTargetVisibility()) ||
917 (!layer_ && visible == visible_)) 914 (!layer() && visible == visible_))
918 return; // No change. 915 return; // No change.
919 916
920 FOR_EACH_OBSERVER(WindowObserver, observers_, 917 FOR_EACH_OBSERVER(WindowObserver, observers_,
921 OnWindowVisibilityChanging(this, visible)); 918 OnWindowVisibilityChanging(this, visible));
922 919
923 WindowTreeHost* host = GetHost(); 920 WindowTreeHost* host = GetHost();
924 if (host) 921 if (host)
925 host->dispatcher()->DispatchMouseExitToHidingWindow(this); 922 host->dispatcher()->DispatchMouseExitToHidingWindow(this);
926 923
927 client::VisibilityClient* visibility_client = 924 client::VisibilityClient* visibility_client =
928 client::GetVisibilityClient(this); 925 client::GetVisibilityClient(this);
929 if (visibility_client) 926 if (visibility_client)
930 visibility_client->UpdateLayerVisibility(this, visible); 927 visibility_client->UpdateLayerVisibility(this, visible);
931 else if (layer_) 928 else if (layer())
932 layer_->SetVisible(visible); 929 layer()->SetVisible(visible);
933 visible_ = visible; 930 visible_ = visible;
934 SchedulePaint(); 931 SchedulePaint();
935 if (parent_ && parent_->layout_manager_) 932 if (parent_ && parent_->layout_manager_)
936 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible); 933 parent_->layout_manager_->OnChildWindowVisibilityChanged(this, visible);
937 934
938 if (delegate_) 935 if (delegate_)
939 delegate_->OnWindowTargetVisibilityChanged(visible); 936 delegate_->OnWindowTargetVisibilityChanged(visible);
940 937
941 NotifyWindowVisibilityChanged(this, visible); 938 NotifyWindowVisibilityChanged(this, visible);
942 939
943 if (host) 940 if (host)
944 host->dispatcher()->OnWindowVisibilityChanged(this, visible); 941 host->dispatcher()->OnWindowVisibilityChanged(this, visible);
945 } 942 }
946 943
947 void Window::SchedulePaint() { 944 void Window::SchedulePaint() {
948 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height())); 945 SchedulePaintInRect(gfx::Rect(0, 0, bounds().width(), bounds().height()));
949 } 946 }
950 947
951 void Window::Paint(gfx::Canvas* canvas) { 948 void Window::Paint(gfx::Canvas* canvas) {
952 if (delegate_) 949 if (delegate_)
953 delegate_->OnPaint(canvas); 950 delegate_->OnPaint(canvas);
954 PaintLayerlessChildren(canvas); 951 PaintLayerlessChildren(canvas);
955 } 952 }
956 953
957 void Window::PaintLayerlessChildren(gfx::Canvas* canvas) { 954 void Window::PaintLayerlessChildren(gfx::Canvas* canvas) {
958 for (size_t i = 0, count = children_.size(); i < count; ++i) { 955 for (size_t i = 0, count = children_.size(); i < count; ++i) {
959 Window* child = children_[i]; 956 Window* child = children_[i];
960 if (!child->layer_ && child->visible_) { 957 if (!child->layer() && child->visible_) {
961 gfx::ScopedCanvas scoped_canvas(canvas); 958 gfx::ScopedCanvas scoped_canvas(canvas);
962 canvas->ClipRect(child->bounds()); 959 canvas->ClipRect(child->bounds());
963 if (!canvas->IsClipEmpty()) { 960 if (!canvas->IsClipEmpty()) {
964 canvas->Translate(child->bounds().OffsetFromOrigin()); 961 canvas->Translate(child->bounds().OffsetFromOrigin());
965 child->Paint(canvas); 962 child->Paint(canvas);
966 } 963 }
967 } 964 }
968 } 965 }
969 } 966 }
970 967
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 Window* root_window = child->GetRootWindow(); 1027 Window* root_window = child->GetRootWindow();
1031 Window* new_root_window = new_parent ? new_parent->GetRootWindow() : NULL; 1028 Window* new_root_window = new_parent ? new_parent->GetRootWindow() : NULL;
1032 if (root_window && root_window != new_root_window) { 1029 if (root_window && root_window != new_root_window) {
1033 root_window->GetHost()->dispatcher()->OnWindowRemovedFromRootWindow( 1030 root_window->GetHost()->dispatcher()->OnWindowRemovedFromRootWindow(
1034 child, new_root_window); 1031 child, new_root_window);
1035 child->NotifyRemovingFromRootWindow(); 1032 child->NotifyRemovingFromRootWindow();
1036 } 1033 }
1037 1034
1038 gfx::Vector2d offset; 1035 gfx::Vector2d offset;
1039 GetAncestorWithLayer(&offset); 1036 GetAncestorWithLayer(&offset);
1040 child->UnparentLayers(!layer_, offset); 1037 child->UnparentLayers(!layer(), offset);
1041 child->parent_ = NULL; 1038 child->parent_ = NULL;
1042 Windows::iterator i = std::find(children_.begin(), children_.end(), child); 1039 Windows::iterator i = std::find(children_.begin(), children_.end(), child);
1043 DCHECK(i != children_.end()); 1040 DCHECK(i != children_.end());
1044 children_.erase(i); 1041 children_.erase(i);
1045 child->OnParentChanged(); 1042 child->OnParentChanged();
1046 if (layout_manager_) 1043 if (layout_manager_)
1047 layout_manager_->OnWindowRemovedFromLayout(child); 1044 layout_manager_->OnWindowRemovedFromLayout(child);
1048 } 1045 }
1049 1046
1050 void Window::UnparentLayers(bool has_layerless_ancestor, 1047 void Window::UnparentLayers(bool has_layerless_ancestor,
1051 const gfx::Vector2d& offset) { 1048 const gfx::Vector2d& offset) {
1052 if (!layer_) { 1049 if (!layer()) {
1053 const gfx::Vector2d new_offset = offset + bounds().OffsetFromOrigin(); 1050 const gfx::Vector2d new_offset = offset + bounds().OffsetFromOrigin();
1054 for (size_t i = 0; i < children_.size(); ++i) { 1051 for (size_t i = 0; i < children_.size(); ++i) {
1055 children_[i]->UnparentLayers(true, new_offset); 1052 children_[i]->UnparentLayers(true, new_offset);
1056 } 1053 }
1057 } else { 1054 } else {
1058 // Only remove the layer if we still own it. Someone else may have acquired 1055 // Only remove the layer if we still own it. Someone else may have acquired
1059 // ownership of it via AcquireLayer() and may expect the hierarchy to go 1056 // ownership of it via AcquireLayer() and may expect the hierarchy to go
1060 // unchanged as the Window is destroyed. 1057 // unchanged as the Window is destroyed.
1061 if (layer_owner_) { 1058 if (OwnsLayer()) {
1062 if (layer_->parent()) 1059 if (layer()->parent())
1063 layer_->parent()->Remove(layer_); 1060 layer()->parent()->Remove(layer());
1064 if (has_layerless_ancestor) { 1061 if (has_layerless_ancestor) {
1065 const gfx::Rect real_bounds(bounds_); 1062 const gfx::Rect real_bounds(bounds_);
1066 gfx::Rect layer_bounds(layer_->bounds()); 1063 gfx::Rect layer_bounds(layer()->bounds());
1067 layer_bounds.Offset(-offset); 1064 layer_bounds.Offset(-offset);
1068 layer_->SetBounds(layer_bounds); 1065 layer()->SetBounds(layer_bounds);
1069 bounds_ = real_bounds; 1066 bounds_ = real_bounds;
1070 } 1067 }
1071 } 1068 }
1072 } 1069 }
1073 } 1070 }
1074 1071
1075 void Window::ReparentLayers(ui::Layer* parent_layer, 1072 void Window::ReparentLayers(ui::Layer* parent_layer,
1076 const gfx::Vector2d& offset) { 1073 const gfx::Vector2d& offset) {
1077 if (!layer_) { 1074 if (!layer()) {
1078 for (size_t i = 0; i < children_.size(); ++i) { 1075 for (size_t i = 0; i < children_.size(); ++i) {
1079 children_[i]->ReparentLayers( 1076 children_[i]->ReparentLayers(
1080 parent_layer, 1077 parent_layer,
1081 offset + children_[i]->bounds().OffsetFromOrigin()); 1078 offset + children_[i]->bounds().OffsetFromOrigin());
1082 } 1079 }
1083 } else { 1080 } else {
1084 const gfx::Rect real_bounds(bounds()); 1081 const gfx::Rect real_bounds(bounds());
1085 parent_layer->Add(layer_); 1082 parent_layer->Add(layer());
1086 gfx::Rect layer_bounds(layer_->bounds().size()); 1083 gfx::Rect layer_bounds(layer()->bounds().size());
1087 layer_bounds += offset; 1084 layer_bounds += offset;
1088 layer_->SetBounds(layer_bounds); 1085 layer()->SetBounds(layer_bounds);
1089 bounds_ = real_bounds; 1086 bounds_ = real_bounds;
1090 } 1087 }
1091 } 1088 }
1092 1089
1093 void Window::OffsetLayerBounds(const gfx::Vector2d& offset) { 1090 void Window::OffsetLayerBounds(const gfx::Vector2d& offset) {
1094 if (!layer_) { 1091 if (!layer()) {
1095 for (size_t i = 0; i < children_.size(); ++i) 1092 for (size_t i = 0; i < children_.size(); ++i)
1096 children_[i]->OffsetLayerBounds(offset); 1093 children_[i]->OffsetLayerBounds(offset);
1097 } else { 1094 } else {
1098 gfx::Rect layer_bounds(layer_->bounds()); 1095 gfx::Rect layer_bounds(layer()->bounds());
1099 layer_bounds += offset; 1096 layer_bounds += offset;
1100 layer_->SetBounds(layer_bounds); 1097 layer()->SetBounds(layer_bounds);
1101 } 1098 }
1102 } 1099 }
1103 1100
1104 void Window::OnParentChanged() { 1101 void Window::OnParentChanged() {
1105 FOR_EACH_OBSERVER( 1102 FOR_EACH_OBSERVER(
1106 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); 1103 WindowObserver, observers_, OnWindowParentChanged(this, parent_));
1107 } 1104 }
1108 1105
1109 void Window::StackChildRelativeTo(Window* child, 1106 void Window::StackChildRelativeTo(Window* child,
1110 Window* target, 1107 Window* target,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 1142
1146 void Window::StackChildLayerRelativeTo(Window* child, 1143 void Window::StackChildLayerRelativeTo(Window* child,
1147 Window* target, 1144 Window* target,
1148 StackDirection direction) { 1145 StackDirection direction) {
1149 Window* ancestor_with_layer = GetAncestorWithLayer(NULL); 1146 Window* ancestor_with_layer = GetAncestorWithLayer(NULL);
1150 ui::Layer* ancestor_layer = 1147 ui::Layer* ancestor_layer =
1151 ancestor_with_layer ? ancestor_with_layer->layer() : NULL; 1148 ancestor_with_layer ? ancestor_with_layer->layer() : NULL;
1152 if (!ancestor_layer) 1149 if (!ancestor_layer)
1153 return; 1150 return;
1154 1151
1155 if (child->layer_ && target->layer_) { 1152 if (child->layer() && target->layer()) {
1156 if (direction == STACK_ABOVE) 1153 if (direction == STACK_ABOVE)
1157 ancestor_layer->StackAbove(child->layer_, target->layer_); 1154 ancestor_layer->StackAbove(child->layer(), target->layer());
1158 else 1155 else
1159 ancestor_layer->StackBelow(child->layer_, target->layer_); 1156 ancestor_layer->StackBelow(child->layer(), target->layer());
1160 return; 1157 return;
1161 } 1158 }
1162 typedef std::vector<ui::Layer*> Layers; 1159 typedef std::vector<ui::Layer*> Layers;
1163 Layers layers; 1160 Layers layers;
1164 GetLayersToStack(child, &layers); 1161 GetLayersToStack(child, &layers);
1165 if (layers.empty()) 1162 if (layers.empty())
1166 return; 1163 return;
1167 1164
1168 ui::Layer* target_layer; 1165 ui::Layer* target_layer;
1169 if (direction == STACK_ABOVE) { 1166 if (direction == STACK_ABOVE) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, 1316 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target,
1320 bool visible) { 1317 bool visible) {
1321 for (Window* window = this; window; window = window->parent()) { 1318 for (Window* window = this; window; window = window->parent()) {
1322 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible); 1319 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible);
1323 DCHECK(ret); 1320 DCHECK(ret);
1324 } 1321 }
1325 } 1322 }
1326 1323
1327 void Window::OnWindowBoundsChanged(const gfx::Rect& old_bounds, 1324 void Window::OnWindowBoundsChanged(const gfx::Rect& old_bounds,
1328 bool contained_mouse) { 1325 bool contained_mouse) {
1329 if (layer_) { 1326 if (layer()) {
1330 bounds_ = layer_->bounds(); 1327 bounds_ = layer()->bounds();
1331 if (parent_ && !parent_->layer_) { 1328 if (parent_ && !parent_->layer()) {
1332 gfx::Vector2d offset; 1329 gfx::Vector2d offset;
1333 aura::Window* ancestor_with_layer = 1330 aura::Window* ancestor_with_layer =
1334 parent_->GetAncestorWithLayer(&offset); 1331 parent_->GetAncestorWithLayer(&offset);
1335 if (ancestor_with_layer) 1332 if (ancestor_with_layer)
1336 bounds_.Offset(-offset); 1333 bounds_.Offset(-offset);
1337 } 1334 }
1338 } 1335 }
1339 1336
1340 if (layout_manager_) 1337 if (layout_manager_)
1341 layout_manager_->OnWindowResized(); 1338 layout_manager_->OnWindowResized();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 } 1400 }
1404 1401
1405 void Window::ConvertEventToTarget(ui::EventTarget* target, 1402 void Window::ConvertEventToTarget(ui::EventTarget* target,
1406 ui::LocatedEvent* event) { 1403 ui::LocatedEvent* event) {
1407 event->ConvertLocationToTarget(this, 1404 event->ConvertLocationToTarget(this,
1408 static_cast<Window*>(target)); 1405 static_cast<Window*>(target));
1409 } 1406 }
1410 1407
1411 void Window::UpdateLayerName(const std::string& name) { 1408 void Window::UpdateLayerName(const std::string& name) {
1412 #if !defined(NDEBUG) 1409 #if !defined(NDEBUG)
1413 DCHECK(layer_); 1410 DCHECK(layer());
1414 1411
1415 std::string layer_name(name_); 1412 std::string layer_name(name_);
1416 if (layer_name.empty()) 1413 if (layer_name.empty())
1417 layer_name = "Unnamed Window"; 1414 layer_name = "Unnamed Window";
1418 1415
1419 if (id_ != -1) 1416 if (id_ != -1)
1420 layer_name += " " + base::IntToString(id_); 1417 layer_name += " " + base::IntToString(id_);
1421 1418
1422 layer_->set_name(layer_name); 1419 layer()->set_name(layer_name);
1423 #endif 1420 #endif
1424 } 1421 }
1425 1422
1426 bool Window::ContainsMouse() { 1423 bool Window::ContainsMouse() {
1427 bool contains_mouse = false; 1424 bool contains_mouse = false;
1428 if (IsVisible()) { 1425 if (IsVisible()) {
1429 WindowTreeHost* host = GetHost(); 1426 WindowTreeHost* host = GetHost();
1430 contains_mouse = host && 1427 contains_mouse = host &&
1431 ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot()); 1428 ContainsPointInRoot(host->dispatcher()->GetLastMouseLocationInRoot());
1432 } 1429 }
1433 return contains_mouse; 1430 return contains_mouse;
1434 } 1431 }
1435 1432
1436 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const { 1433 const Window* Window::GetAncestorWithLayer(gfx::Vector2d* offset) const {
1437 for (const aura::Window* window = this; window; window = window->parent()) { 1434 for (const aura::Window* window = this; window; window = window->parent()) {
1438 if (window->layer_) 1435 if (window->layer())
1439 return window; 1436 return window;
1440 if (offset) 1437 if (offset)
1441 *offset += window->bounds().OffsetFromOrigin(); 1438 *offset += window->bounds().OffsetFromOrigin();
1442 } 1439 }
1443 if (offset) 1440 if (offset)
1444 *offset = gfx::Vector2d(); 1441 *offset = gfx::Vector2d();
1445 return NULL; 1442 return NULL;
1446 } 1443 }
1447 1444
1448 } // namespace aura 1445 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/window_test_api.cc ('k') | ui/compositor/layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698