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

Side by Side Diff: ui/views/mus/native_widget_mus.cc

Issue 2579883002: Scale bounds in aura-mus client-lib and NativeWidgetMus in hdpi mode. (Closed)
Patch Set: Created 4 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This has to be before any other includes, else default is picked up. 5 // This has to be before any other includes, else default is picked up.
6 // See base/logging for details on this. 6 // See base/logging for details on this.
7 #define NOTIMPLEMENTED_POLICY 5 7 #define NOTIMPLEMENTED_POLICY 5
8 8
9 #include "ui/views/mus/native_widget_mus.h" 9 #include "ui/views/mus/native_widget_mus.h"
10 10
(...skipping 20 matching lines...) Expand all
31 #include "ui/aura/layout_manager.h" 31 #include "ui/aura/layout_manager.h"
32 #include "ui/aura/mus/mus_util.h" 32 #include "ui/aura/mus/mus_util.h"
33 #include "ui/aura/mus/property_converter.h" 33 #include "ui/aura/mus/property_converter.h"
34 #include "ui/aura/window.h" 34 #include "ui/aura/window.h"
35 #include "ui/aura/window_property.h" 35 #include "ui/aura/window_property.h"
36 #include "ui/base/hit_test.h" 36 #include "ui/base/hit_test.h"
37 #include "ui/display/display.h" 37 #include "ui/display/display.h"
38 #include "ui/display/screen.h" 38 #include "ui/display/screen.h"
39 #include "ui/events/event.h" 39 #include "ui/events/event.h"
40 #include "ui/gfx/canvas.h" 40 #include "ui/gfx/canvas.h"
41 #include "ui/gfx/geometry/dip_util.h"
41 #include "ui/gfx/path.h" 42 #include "ui/gfx/path.h"
42 #include "ui/native_theme/native_theme.h" 43 #include "ui/native_theme/native_theme.h"
43 #include "ui/platform_window/platform_window_delegate.h" 44 #include "ui/platform_window/platform_window_delegate.h"
44 #include "ui/views/corewm/tooltip.h" 45 #include "ui/views/corewm/tooltip.h"
45 #include "ui/views/corewm/tooltip_aura.h" 46 #include "ui/views/corewm/tooltip_aura.h"
46 #include "ui/views/corewm/tooltip_controller.h" 47 #include "ui/views/corewm/tooltip_controller.h"
47 #include "ui/views/drag_utils.h" 48 #include "ui/views/drag_utils.h"
48 #include "ui/views/mus/drag_drop_client_mus.h" 49 #include "ui/views/mus/drag_drop_client_mus.h"
49 #include "ui/views/mus/drop_target_mus.h" 50 #include "ui/views/mus/drop_target_mus.h"
50 #include "ui/views/mus/input_method_mus.h" 51 #include "ui/views/mus/input_method_mus.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 const char* const property, 388 const char* const property,
388 const gfx::ImageSkia& icon) { 389 const gfx::ImageSkia& icon) {
389 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. 390 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
390 SkBitmap bitmap = icon.GetRepresentation(1.f).sk_bitmap(); 391 SkBitmap bitmap = icon.GetRepresentation(1.f).sk_bitmap();
391 if (!bitmap.isNull()) 392 if (!bitmap.isNull())
392 window->SetSharedProperty<SkBitmap>(property, bitmap); 393 window->SetSharedProperty<SkBitmap>(property, bitmap);
393 else if (window->HasSharedProperty(property)) 394 else if (window->HasSharedProperty(property))
394 window->ClearSharedProperty(property); 395 window->ClearSharedProperty(property);
395 } 396 }
396 397
398 // Helper function to get the device_scale_factor() of the display::Display
399 // nearest to |window|.
400 float ScaleFactorForDisplay(aura::Window* window) {
401 return display::Screen::GetScreen()
402 ->GetDisplayNearestWindow(window)
403 .device_scale_factor();
404 }
405
397 } // namespace 406 } // namespace
398 407
399 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver { 408 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver {
400 public: 409 public:
401 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) 410 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus)
402 : native_widget_mus_(native_widget_mus), 411 : native_widget_mus_(native_widget_mus),
403 show_state_(ui::mojom::ShowState::DEFAULT) { 412 show_state_(ui::mojom::ShowState::DEFAULT) {
404 mus_window()->AddObserver(this); 413 mus_window()->AddObserver(this);
405 } 414 }
406 415
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 platform_window_delegate()->OnWindowStateChanged(state); 462 platform_window_delegate()->OnWindowStateChanged(state);
454 } 463 }
455 void OnWindowDestroyed(ui::Window* window) override { 464 void OnWindowDestroyed(ui::Window* window) override {
456 DCHECK_EQ(mus_window(), window); 465 DCHECK_EQ(mus_window(), window);
457 platform_window_delegate()->OnClosed(); 466 platform_window_delegate()->OnClosed();
458 } 467 }
459 void OnWindowBoundsChanging(ui::Window* window, 468 void OnWindowBoundsChanging(ui::Window* window,
460 const gfx::Rect& old_bounds, 469 const gfx::Rect& old_bounds,
461 const gfx::Rect& new_bounds) override { 470 const gfx::Rect& new_bounds) override {
462 DCHECK_EQ(window, mus_window()); 471 DCHECK_EQ(window, mus_window());
463 window_tree_host()->SetBoundsInPixels(new_bounds); 472 window_tree_host()->SetBoundsInPixels(gfx::ConvertRectToPixel(
473 ScaleFactorForDisplay(aura_window()), new_bounds));
464 } 474 }
465 void OnWindowFocusChanged(ui::Window* gained_focus, 475 void OnWindowFocusChanged(ui::Window* gained_focus,
466 ui::Window* lost_focus) override { 476 ui::Window* lost_focus) override {
467 if (gained_focus == mus_window()) 477 if (gained_focus == mus_window())
468 platform_window_delegate()->OnActivationChanged(true); 478 platform_window_delegate()->OnActivationChanged(true);
469 else if (lost_focus == mus_window()) 479 else if (lost_focus == mus_window())
470 platform_window_delegate()->OnActivationChanged(false); 480 platform_window_delegate()->OnActivationChanged(false);
471 } 481 }
472 void OnRequestClose(ui::Window* window) override { 482 void OnRequestClose(ui::Window* window) override {
473 platform_window_delegate()->OnCloseRequest(); 483 platform_window_delegate()->OnCloseRequest();
474 } 484 }
475 485
476 private: 486 private:
477 ui::Window* mus_window() { return native_widget_mus_->window(); } 487 ui::Window* mus_window() { return native_widget_mus_->window(); }
488 aura::Window* aura_window() { return native_widget_mus_->aura_window(); }
478 WindowTreeHostMus* window_tree_host() { 489 WindowTreeHostMus* window_tree_host() {
479 return native_widget_mus_->window_tree_host(); 490 return native_widget_mus_->window_tree_host();
480 } 491 }
481 ui::PlatformWindowDelegate* platform_window_delegate() { 492 ui::PlatformWindowDelegate* platform_window_delegate() {
482 return native_widget_mus_->window_tree_host(); 493 return native_widget_mus_->window_tree_host();
483 } 494 }
484 495
485 NativeWidgetMus* native_widget_mus_; 496 NativeWidgetMus* native_widget_mus_;
486 ui::mojom::ShowState show_state_; 497 ui::mojom::ShowState show_state_;
487 498
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 origin.Offset(-display_origin.x(), -display_origin.y()); 1022 origin.Offset(-display_origin.x(), -display_origin.y());
1012 1023
1013 gfx::Size size(bounds_in_screen.size()); 1024 gfx::Size size(bounds_in_screen.size());
1014 const gfx::Size min_size = GetMinimumSize(); 1025 const gfx::Size min_size = GetMinimumSize();
1015 const gfx::Size max_size = GetMaximumSize(); 1026 const gfx::Size max_size = GetMaximumSize();
1016 if (!max_size.IsEmpty()) 1027 if (!max_size.IsEmpty())
1017 size.SetToMin(max_size); 1028 size.SetToMin(max_size);
1018 size.SetToMax(min_size); 1029 size.SetToMax(min_size);
1019 window_->SetBounds(gfx::Rect(origin, size)); 1030 window_->SetBounds(gfx::Rect(origin, size));
1020 // Observer on |window_tree_host_| expected to synchronously update bounds. 1031 // Observer on |window_tree_host_| expected to synchronously update bounds.
1021 DCHECK(window_->bounds() == window_tree_host_->GetBoundsInPixels()); 1032 DCHECK(gfx::ConvertRectToPixel(ScaleFactorForDisplay(content_),
1033 window_->bounds()) ==
1034 window_tree_host_->GetBoundsInPixels());
sadrul 2016/12/16 18:14:08 DCHECK_EQ
riajiang 2016/12/19 23:51:55 Done.
1022 } 1035 }
1023 1036
1024 void NativeWidgetMus::SetSize(const gfx::Size& size) { 1037 void NativeWidgetMus::SetSize(const gfx::Size& size) {
1025 if (!window_tree_host_) 1038 if (!window_tree_host_)
1026 return; 1039 return;
1027 1040
1028 gfx::Rect bounds = window_tree_host_->GetBoundsInPixels(); 1041 gfx::Rect bounds = window_tree_host_->GetBoundsInPixels();
1029 SetBounds(gfx::Rect(bounds.origin(), size)); 1042 SetBounds(gfx::Rect(bounds.origin(), size));
1030 } 1043 }
1031 1044
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 1578
1566 gfx::Path mask_path; 1579 gfx::Path mask_path;
1567 native_widget_delegate_->GetHitTestMask(&mask_path); 1580 native_widget_delegate_->GetHitTestMask(&mask_path);
1568 // TODO(jamescook): Use the full path for the mask. 1581 // TODO(jamescook): Use the full path for the mask.
1569 gfx::Rect mask_rect = 1582 gfx::Rect mask_rect =
1570 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1583 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1571 window_->SetHitTestMask(mask_rect); 1584 window_->SetHitTestMask(mask_rect);
1572 } 1585 }
1573 1586
1574 } // namespace views 1587 } // namespace views
OLDNEW
« ui/aura/mus/window_tree_client.cc ('K') | « ui/views/mus/native_widget_mus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698