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

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

Issue 10827145: Convert Aura to use ui::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/window.h ('k') | ui/aura/window_delegate.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"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "ui/aura/client/capture_client.h" 16 #include "ui/aura/client/capture_client.h"
17 #include "ui/aura/client/event_client.h" 17 #include "ui/aura/client/event_client.h"
18 #include "ui/aura/client/screen_position_client.h" 18 #include "ui/aura/client/screen_position_client.h"
19 #include "ui/aura/client/stacking_client.h" 19 #include "ui/aura/client/stacking_client.h"
20 #include "ui/aura/client/visibility_client.h" 20 #include "ui/aura/client/visibility_client.h"
21 #include "ui/aura/env.h" 21 #include "ui/aura/env.h"
22 #include "ui/aura/event.h"
23 #include "ui/aura/event_filter.h" 22 #include "ui/aura/event_filter.h"
24 #include "ui/aura/focus_manager.h" 23 #include "ui/aura/focus_manager.h"
25 #include "ui/aura/layout_manager.h" 24 #include "ui/aura/layout_manager.h"
26 #include "ui/aura/root_window.h" 25 #include "ui/aura/root_window.h"
27 #include "ui/aura/window_delegate.h" 26 #include "ui/aura/window_delegate.h"
28 #include "ui/aura/window_observer.h" 27 #include "ui/aura/window_observer.h"
29 #include "ui/base/animation/multi_animation.h" 28 #include "ui/base/animation/multi_animation.h"
30 #include "ui/compositor/compositor.h" 29 #include "ui/compositor/compositor.h"
31 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
32 #include "ui/gfx/canvas.h" 31 #include "ui/gfx/canvas.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return visible_ && layer_ && layer_->IsDrawn(); 235 return visible_ && layer_ && layer_->IsDrawn();
237 } 236 }
238 237
239 gfx::Rect Window::GetBoundsInRootWindow() const { 238 gfx::Rect Window::GetBoundsInRootWindow() const {
240 // TODO(beng): There may be a better way to handle this, and the existing code 239 // TODO(beng): There may be a better way to handle this, and the existing code
241 // is likely wrong anyway in a multi-display world, but this will 240 // is likely wrong anyway in a multi-display world, but this will
242 // do for now. 241 // do for now.
243 if (!GetRootWindow()) 242 if (!GetRootWindow())
244 return bounds(); 243 return bounds();
245 gfx::Point origin = bounds().origin(); 244 gfx::Point origin = bounds().origin();
246 Window::ConvertPointToWindow(parent_, GetRootWindow(), &origin); 245 ConvertPointToTarget(parent_, GetRootWindow(), &origin);
247 return gfx::Rect(origin, bounds().size()); 246 return gfx::Rect(origin, bounds().size());
248 } 247 }
249 248
250 gfx::Rect Window::GetBoundsInScreen() const { 249 gfx::Rect Window::GetBoundsInScreen() const {
251 gfx::Rect bounds(GetBoundsInRootWindow()); 250 gfx::Rect bounds(GetBoundsInRootWindow());
252 const RootWindow* root = GetRootWindow(); 251 const RootWindow* root = GetRootWindow();
253 if (root) { 252 if (root) {
254 aura::client::ScreenPositionClient* screen_position_client = 253 aura::client::ScreenPositionClient* screen_position_client =
255 aura::client::GetScreenPositionClient(root); 254 aura::client::GetScreenPositionClient(root);
256 if (screen_position_client) { 255 if (screen_position_client) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 if ((*i)->id() == id) 424 if ((*i)->id() == id)
426 return *i; 425 return *i;
427 const Window* result = (*i)->GetChildById(id); 426 const Window* result = (*i)->GetChildById(id);
428 if (result) 427 if (result)
429 return result; 428 return result;
430 } 429 }
431 return NULL; 430 return NULL;
432 } 431 }
433 432
434 // static 433 // static
435 void Window::ConvertPointToWindow(const Window* source, 434 void Window::ConvertPointToTarget(const Window* source,
436 const Window* target, 435 const Window* target,
437 gfx::Point* point) { 436 gfx::Point* point) {
438 if (!source) 437 if (!source)
439 return; 438 return;
440 if (source->GetRootWindow() != target->GetRootWindow()) { 439 if (source->GetRootWindow() != target->GetRootWindow()) {
441 const gfx::Point source_origin = 440 const gfx::Point source_origin =
442 gfx::Screen::GetDisplayNearestWindow( 441 gfx::Screen::GetDisplayNearestWindow(
443 const_cast<Window*>(source)).bounds().origin(); 442 const_cast<Window*>(source)).bounds().origin();
444 const gfx::Point target_origin = 443 const gfx::Point target_origin =
445 gfx::Screen::GetDisplayNearestWindow( 444 gfx::Screen::GetDisplayNearestWindow(
446 const_cast<Window*>(target)).bounds().origin(); 445 const_cast<Window*>(target)).bounds().origin();
447 ui::Layer::ConvertPointToLayer( 446 ui::Layer::ConvertPointToLayer(
448 source->layer(), source->GetRootWindow()->layer(), point); 447 source->layer(), source->GetRootWindow()->layer(), point);
449 const gfx::Point offset = source_origin.Subtract(target_origin); 448 const gfx::Point offset = source_origin.Subtract(target_origin);
450 point->Offset(offset.x(), offset.y()); 449 point->Offset(offset.x(), offset.y());
451 ui::Layer::ConvertPointToLayer( 450 ui::Layer::ConvertPointToLayer(
452 target->GetRootWindow()->layer(), target->layer(), point); 451 target->GetRootWindow()->layer(), target->layer(), point);
453 } else { 452 } else {
454 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); 453 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point);
455 } 454 }
456 } 455 }
457 456
458 void Window::MoveCursorTo(const gfx::Point& point_in_window) { 457 void Window::MoveCursorTo(const gfx::Point& point_in_window) {
459 RootWindow* root_window = GetRootWindow(); 458 RootWindow* root_window = GetRootWindow();
460 DCHECK(root_window); 459 DCHECK(root_window);
461 gfx::Point point_in_root(point_in_window); 460 gfx::Point point_in_root(point_in_window);
462 ConvertPointToWindow(this, root_window, &point_in_root); 461 ConvertPointToTarget(this, root_window, &point_in_root);
463 root_window->MoveCursorTo(point_in_root); 462 root_window->MoveCursorTo(point_in_root);
464 } 463 }
465 464
466 gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const { 465 gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const {
467 return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor; 466 return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor;
468 } 467 }
469 468
470 void Window::SetEventFilter(EventFilter* event_filter) { 469 void Window::SetEventFilter(EventFilter* event_filter) {
471 event_filter_.reset(event_filter); 470 event_filter_.reset(event_filter);
472 } 471 }
473 472
474 void Window::AddObserver(WindowObserver* observer) { 473 void Window::AddObserver(WindowObserver* observer) {
475 observers_.AddObserver(observer); 474 observers_.AddObserver(observer);
476 } 475 }
477 476
478 void Window::RemoveObserver(WindowObserver* observer) { 477 void Window::RemoveObserver(WindowObserver* observer) {
479 observers_.RemoveObserver(observer); 478 observers_.RemoveObserver(observer);
480 } 479 }
481 480
482 bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const { 481 bool Window::ContainsPointInRoot(const gfx::Point& point_in_root) const {
483 const Window* root_window = GetRootWindow(); 482 const Window* root_window = GetRootWindow();
484 if (!root_window) 483 if (!root_window)
485 return false; 484 return false;
486 gfx::Point local_point(point_in_root); 485 gfx::Point local_point(point_in_root);
487 ConvertPointToWindow(root_window, this, &local_point); 486 ConvertPointToTarget(root_window, this, &local_point);
488 return gfx::Rect(GetTargetBounds().size()).Contains(local_point); 487 return gfx::Rect(GetTargetBounds().size()).Contains(local_point);
489 } 488 }
490 489
491 bool Window::ContainsPoint(const gfx::Point& local_point) const { 490 bool Window::ContainsPoint(const gfx::Point& local_point) const {
492 return gfx::Rect(bounds().size()).Contains(local_point); 491 return gfx::Rect(bounds().size()).Contains(local_point);
493 } 492 }
494 493
495 bool Window::HitTest(const gfx::Point& local_point) { 494 bool Window::HitTest(const gfx::Point& local_point) {
496 // Expand my bounds for hit testing (override is usually zero but it's 495 // Expand my bounds for hit testing (override is usually zero but it's
497 // probably cheaper to do the math every time than to branch). 496 // probably cheaper to do the math every time than to branch).
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 if (client && !client->CanProcessEventsWithinSubtree(child)) 745 if (client && !client->CanProcessEventsWithinSubtree(child))
747 continue; 746 continue;
748 } 747 }
749 748
750 // We don't process events for invisible windows or those that have asked 749 // We don't process events for invisible windows or those that have asked
751 // to ignore events. 750 // to ignore events.
752 if (!child->IsVisible() || (for_event_handling && child->ignore_events_)) 751 if (!child->IsVisible() || (for_event_handling && child->ignore_events_))
753 continue; 752 continue;
754 753
755 gfx::Point point_in_child_coords(local_point); 754 gfx::Point point_in_child_coords(local_point);
756 Window::ConvertPointToWindow(this, child, &point_in_child_coords); 755 ConvertPointToTarget(this, child, &point_in_child_coords);
757 if (for_event_handling && delegate_ && 756 if (for_event_handling && delegate_ &&
758 !delegate_->ShouldDescendIntoChildForEventHandling( 757 !delegate_->ShouldDescendIntoChildForEventHandling(
759 child, local_point)) { 758 child, local_point)) {
760 continue; 759 continue;
761 } 760 }
762 761
763 Window* match = child->GetWindowForPoint(point_in_child_coords, 762 Window* match = child->GetWindowForPoint(point_in_child_coords,
764 return_tightest, 763 return_tightest,
765 for_event_handling); 764 for_event_handling);
766 if (match) 765 if (match)
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 for (Windows::const_reverse_iterator it = children_.rbegin(), 941 for (Windows::const_reverse_iterator it = children_.rbegin(),
943 rend = children_.rend(); 942 rend = children_.rend();
944 it != rend; ++it) { 943 it != rend; ++it) {
945 Window* child = *it; 944 Window* child = *it;
946 child->PrintWindowHierarchy(depth + 1); 945 child->PrintWindowHierarchy(depth + 1);
947 } 946 }
948 } 947 }
949 #endif 948 #endif
950 949
951 } // namespace aura 950 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698