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