| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "ui/aura/client/event_client.h" | 13 #include "ui/aura/client/event_client.h" |
| 14 #include "ui/aura/client/stacking_client.h" | 14 #include "ui/aura/client/stacking_client.h" |
| 15 #include "ui/aura/client/visibility_client.h" | 15 #include "ui/aura/client/visibility_client.h" |
| 16 #include "ui/aura/dip_util.h" | |
| 17 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 18 #include "ui/aura/event.h" | 17 #include "ui/aura/event.h" |
| 19 #include "ui/aura/event_filter.h" | 18 #include "ui/aura/event_filter.h" |
| 20 #include "ui/aura/layout_manager.h" | 19 #include "ui/aura/layout_manager.h" |
| 21 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
| 22 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
| 23 #include "ui/aura/window_observer.h" | 22 #include "ui/aura/window_observer.h" |
| 24 #include "ui/base/animation/multi_animation.h" | 23 #include "ui/base/animation/multi_animation.h" |
| 25 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 26 #include "ui/gfx/compositor/compositor.h" | 25 #include "ui/gfx/compositor/compositor.h" |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // TODO(beng): There may be a better way to handle this, and the existing code | 204 // TODO(beng): There may be a better way to handle this, and the existing code |
| 206 // is likely wrong anyway in a multi-monitor world, but this will | 205 // is likely wrong anyway in a multi-monitor world, but this will |
| 207 // do for now. | 206 // do for now. |
| 208 if (!GetRootWindow()) | 207 if (!GetRootWindow()) |
| 209 return bounds(); | 208 return bounds(); |
| 210 gfx::Point origin = bounds().origin(); | 209 gfx::Point origin = bounds().origin(); |
| 211 Window::ConvertPointToWindow(parent_, GetRootWindow(), &origin); | 210 Window::ConvertPointToWindow(parent_, GetRootWindow(), &origin); |
| 212 return gfx::Rect(origin, bounds().size()); | 211 return gfx::Rect(origin, bounds().size()); |
| 213 } | 212 } |
| 214 | 213 |
| 215 const gfx::Rect& Window::GetBoundsInPixel() const { | |
| 216 return layer_->bounds(); | |
| 217 } | |
| 218 | |
| 219 void Window::SetTransform(const ui::Transform& transform) { | 214 void Window::SetTransform(const ui::Transform& transform) { |
| 220 RootWindow* root_window = GetRootWindow(); | 215 RootWindow* root_window = GetRootWindow(); |
| 221 bool contained_mouse = IsVisible() && root_window && | 216 bool contained_mouse = IsVisible() && root_window && |
| 222 ContainsPointInRoot(root_window->last_mouse_location()); | 217 ContainsPointInRoot(root_window->last_mouse_location()); |
| 223 layer()->SetTransform(transform); | 218 layer()->SetTransform(transform); |
| 224 if (root_window) | 219 if (root_window) |
| 225 root_window->OnWindowTransformed(this, contained_mouse); | 220 root_window->OnWindowTransformed(this, contained_mouse); |
| 226 } | 221 } |
| 227 | 222 |
| 228 void Window::SetLayoutManager(LayoutManager* layout_manager) { | 223 void Window::SetLayoutManager(LayoutManager* layout_manager) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 240 } | 235 } |
| 241 | 236 |
| 242 void Window::SetBounds(const gfx::Rect& new_bounds) { | 237 void Window::SetBounds(const gfx::Rect& new_bounds) { |
| 243 if (parent_ && parent_->layout_manager()) | 238 if (parent_ && parent_->layout_manager()) |
| 244 parent_->layout_manager()->SetChildBounds(this, new_bounds); | 239 parent_->layout_manager()->SetChildBounds(this, new_bounds); |
| 245 else | 240 else |
| 246 SetBoundsInternal(new_bounds); | 241 SetBoundsInternal(new_bounds); |
| 247 } | 242 } |
| 248 | 243 |
| 249 gfx::Rect Window::GetTargetBounds() const { | 244 gfx::Rect Window::GetTargetBounds() const { |
| 250 return ConvertRectToDIP(this, layer_->GetTargetBounds()); | 245 return layer_->GetTargetBounds(); |
| 251 } | 246 } |
| 252 | 247 |
| 253 gfx::Rect Window::bounds() const { | 248 const gfx::Rect& Window::bounds() const { |
| 254 #if defined(ENABLE_DIP) | |
| 255 return ConvertRectToDIP(this, layer_->bounds()); | |
| 256 #else | |
| 257 return layer_->bounds(); | 249 return layer_->bounds(); |
| 258 #endif | |
| 259 } | 250 } |
| 260 | 251 |
| 261 void Window::SchedulePaintInRect(const gfx::Rect& rect_in_dip) { | 252 void Window::SchedulePaintInRect(const gfx::Rect& rect) { |
| 262 gfx::Rect rect = ConvertRectToPixel(this, rect_in_dip); | |
| 263 if (layer_->SchedulePaint(rect)) { | 253 if (layer_->SchedulePaint(rect)) { |
| 264 FOR_EACH_OBSERVER( | 254 FOR_EACH_OBSERVER( |
| 265 WindowObserver, observers_, OnWindowPaintScheduled(this, rect_in_dip)); | 255 WindowObserver, observers_, OnWindowPaintScheduled(this, rect)); |
| 266 } | 256 } |
| 267 } | 257 } |
| 268 | 258 |
| 269 void Window::SetExternalTexture(ui::Texture* texture) { | 259 void Window::SetExternalTexture(ui::Texture* texture) { |
| 270 layer_->SetExternalTexture(texture); | 260 layer_->SetExternalTexture(texture); |
| 271 gfx::Rect region(bounds().size()); | 261 gfx::Rect region(bounds().size()); |
| 272 FOR_EACH_OBSERVER( | 262 FOR_EACH_OBSERVER( |
| 273 WindowObserver, observers_, OnWindowPaintScheduled(this, region)); | 263 WindowObserver, observers_, OnWindowPaintScheduled(this, region)); |
| 274 } | 264 } |
| 275 | 265 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 367 } |
| 378 return NULL; | 368 return NULL; |
| 379 } | 369 } |
| 380 | 370 |
| 381 // static | 371 // static |
| 382 void Window::ConvertPointToWindow(const Window* source, | 372 void Window::ConvertPointToWindow(const Window* source, |
| 383 const Window* target, | 373 const Window* target, |
| 384 gfx::Point* point) { | 374 gfx::Point* point) { |
| 385 if (!source) | 375 if (!source) |
| 386 return; | 376 return; |
| 387 // TODO(oshima): We probably need to handle source's root != target's root | |
| 388 // case under multi monitor environment. | |
| 389 *point = ConvertPointToPixel(source, *point); | |
| 390 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); | 377 ui::Layer::ConvertPointToLayer(source->layer(), target->layer(), point); |
| 391 if (target) | |
| 392 *point = ConvertPointToDIP(target, *point); | |
| 393 else | |
| 394 *point = ConvertPointToDIP(source, *point); | |
| 395 } | 378 } |
| 396 | 379 |
| 397 gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const { | 380 gfx::NativeCursor Window::GetCursor(const gfx::Point& point) const { |
| 398 return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor; | 381 return delegate_ ? delegate_->GetCursor(point) : gfx::kNullCursor; |
| 399 } | 382 } |
| 400 | 383 |
| 401 void Window::SetEventFilter(EventFilter* event_filter) { | 384 void Window::SetEventFilter(EventFilter* event_filter) { |
| 402 event_filter_.reset(event_filter); | 385 event_filter_.reset(event_filter); |
| 403 } | 386 } |
| 404 | 387 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 RootWindow* root_window = GetRootWindow(); | 571 RootWindow* root_window = GetRootWindow(); |
| 589 | 572 |
| 590 bool contained_mouse = | 573 bool contained_mouse = |
| 591 IsVisible() && | 574 IsVisible() && |
| 592 root_window && ContainsPointInRoot(root_window->last_mouse_location()); | 575 root_window && ContainsPointInRoot(root_window->last_mouse_location()); |
| 593 | 576 |
| 594 const gfx::Rect old_bounds = GetTargetBounds(); | 577 const gfx::Rect old_bounds = GetTargetBounds(); |
| 595 | 578 |
| 596 // Always need to set the layer's bounds -- even if it is to the same thing. | 579 // Always need to set the layer's bounds -- even if it is to the same thing. |
| 597 // This may cause important side effects such as stopping animation. | 580 // This may cause important side effects such as stopping animation. |
| 598 layer_->SetBounds(ConvertRectToPixel(this, actual_new_bounds)); | 581 layer_->SetBounds(actual_new_bounds); |
| 599 | 582 |
| 600 // If we're not changing the effective bounds, then we can bail early and skip | 583 // If we're not changing the effective bounds, then we can bail early and skip |
| 601 // notifying our listeners. | 584 // notifying our listeners. |
| 602 if (old_bounds == actual_new_bounds) | 585 if (old_bounds == actual_new_bounds) |
| 603 return; | 586 return; |
| 604 | 587 |
| 605 if (layout_manager_.get()) | 588 if (layout_manager_.get()) |
| 606 layout_manager_->OnWindowResized(); | 589 layout_manager_->OnWindowResized(); |
| 607 if (delegate_) | 590 if (delegate_) |
| 608 delegate_->OnBoundsChanged(old_bounds, actual_new_bounds); | 591 delegate_->OnBoundsChanged(old_bounds, actual_new_bounds); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 void Window::NotifyAddedToRootWindow() { | 785 void Window::NotifyAddedToRootWindow() { |
| 803 FOR_EACH_OBSERVER(WindowObserver, observers_, | 786 FOR_EACH_OBSERVER(WindowObserver, observers_, |
| 804 OnWindowAddedToRootWindow(this)); | 787 OnWindowAddedToRootWindow(this)); |
| 805 for (Window::Windows::const_iterator it = children_.begin(); | 788 for (Window::Windows::const_iterator it = children_.begin(); |
| 806 it != children_.end(); ++it) { | 789 it != children_.end(); ++it) { |
| 807 (*it)->NotifyAddedToRootWindow(); | 790 (*it)->NotifyAddedToRootWindow(); |
| 808 } | 791 } |
| 809 } | 792 } |
| 810 | 793 |
| 811 void Window::OnPaintLayer(gfx::Canvas* canvas) { | 794 void Window::OnPaintLayer(gfx::Canvas* canvas) { |
| 812 if (delegate_) { | 795 if (delegate_) |
| 813 #if defined(ENABLE_DIP) | |
| 814 float scale = GetMonitorScaleFactor(this); | |
| 815 canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale)); | |
| 816 #endif | |
| 817 delegate_->OnPaint(canvas); | 796 delegate_->OnPaint(canvas); |
| 818 #if defined(ENABLE_DIP) | |
| 819 canvas->Restore(); | |
| 820 #endif | |
| 821 } | |
| 822 } | 797 } |
| 823 | 798 |
| 824 void Window::UpdateLayerName(const std::string& name) { | 799 void Window::UpdateLayerName(const std::string& name) { |
| 825 #if !defined(NDEBUG) | 800 #if !defined(NDEBUG) |
| 826 DCHECK(layer()); | 801 DCHECK(layer()); |
| 827 | 802 |
| 828 std::string layer_name(name_); | 803 std::string layer_name(name_); |
| 829 if (layer_name.empty()) | 804 if (layer_name.empty()) |
| 830 layer_name.append("Unnamed Window"); | 805 layer_name.append("Unnamed Window"); |
| 831 | 806 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 852 for (Windows::const_reverse_iterator it = children_.rbegin(), | 827 for (Windows::const_reverse_iterator it = children_.rbegin(), |
| 853 rend = children_.rend(); | 828 rend = children_.rend(); |
| 854 it != rend; ++it) { | 829 it != rend; ++it) { |
| 855 Window* child = *it; | 830 Window* child = *it; |
| 856 child->PrintWindowHierarchy(depth + 1); | 831 child->PrintWindowHierarchy(depth + 1); |
| 857 } | 832 } |
| 858 } | 833 } |
| 859 #endif | 834 #endif |
| 860 | 835 |
| 861 } // namespace aura | 836 } // namespace aura |
| OLD | NEW |