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

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

Issue 2519583002: Add gfx::ImageSkia and icon support to aura::PropertyConverter. (Closed)
Patch Set: Fix ConvertPropertyForTransport; add unit test. Created 4 years, 1 month 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
« no previous file with comments | « ui/aura/mus/property_converter_unittest.cc ('k') | ui/views/mus/native_widget_mus_unittest.cc » ('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 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 int32_t behavior = ui::mojom::kResizeBehaviorNone; 330 int32_t behavior = ui::mojom::kResizeBehaviorNone;
331 if (delegate->CanResize()) 331 if (delegate->CanResize())
332 behavior |= ui::mojom::kResizeBehaviorCanResize; 332 behavior |= ui::mojom::kResizeBehaviorCanResize;
333 if (delegate->CanMaximize()) 333 if (delegate->CanMaximize())
334 behavior |= ui::mojom::kResizeBehaviorCanMaximize; 334 behavior |= ui::mojom::kResizeBehaviorCanMaximize;
335 if (delegate->CanMinimize()) 335 if (delegate->CanMinimize())
336 behavior |= ui::mojom::kResizeBehaviorCanMinimize; 336 behavior |= ui::mojom::kResizeBehaviorCanMinimize;
337 return behavior; 337 return behavior;
338 } 338 }
339 339
340 // Returns the 1x window app icon or an empty SkBitmap if no icon is available.
341 // TODO(jamescook): Support other scale factors.
342 SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) {
343 if (!delegate)
344 return SkBitmap();
345 gfx::ImageSkia app_icon = delegate->GetWindowAppIcon();
346 if (app_icon.isNull())
347 return SkBitmap();
348 return app_icon.GetRepresentation(1.f).sk_bitmap();
349 }
350
351 // Handles acknowledgment of an input event, either immediately when a nested 340 // Handles acknowledgment of an input event, either immediately when a nested
352 // message loop starts, or upon destruction. 341 // message loop starts, or upon destruction.
353 class EventAckHandler : public base::MessageLoop::NestingObserver { 342 class EventAckHandler : public base::MessageLoop::NestingObserver {
354 public: 343 public:
355 explicit EventAckHandler( 344 explicit EventAckHandler(
356 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) 345 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback)
357 : ack_callback_(std::move(ack_callback)) { 346 : ack_callback_(std::move(ack_callback)) {
358 DCHECK(ack_callback_); 347 DCHECK(ack_callback_);
359 base::MessageLoop::current()->AddNestingObserver(this); 348 base::MessageLoop::current()->AddNestingObserver(this);
360 } 349 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (!window || 386 if (!window ||
398 !window->HasSharedProperty( 387 !window->HasSharedProperty(
399 ui::mojom::WindowManager::kShowState_Property)) { 388 ui::mojom::WindowManager::kShowState_Property)) {
400 return ui::mojom::ShowState::DEFAULT; 389 return ui::mojom::ShowState::DEFAULT;
401 } 390 }
402 391
403 return static_cast<ui::mojom::ShowState>(window->GetSharedProperty<int32_t>( 392 return static_cast<ui::mojom::ShowState>(window->GetSharedProperty<int32_t>(
404 ui::mojom::WindowManager::kShowState_Property)); 393 ui::mojom::WindowManager::kShowState_Property));
405 } 394 }
406 395
396 // Set the app or window icon property for the window.
397 void SetIconProperty(ui::Window* window,
398 const char* const property,
399 const gfx::ImageSkia& icon) {
400 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
401 SkBitmap bitmap = icon.GetRepresentation(1.f).sk_bitmap();
402 if (!bitmap.isNull())
403 window->SetSharedProperty<SkBitmap>(property, bitmap);
404 else if (window->HasSharedProperty(property))
405 window->ClearSharedProperty(property);
406 }
407
407 } // namespace 408 } // namespace
408 409
409 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver { 410 class NativeWidgetMus::MusWindowObserver : public ui::WindowObserver {
410 public: 411 public:
411 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus) 412 explicit MusWindowObserver(NativeWidgetMus* native_widget_mus)
412 : native_widget_mus_(native_widget_mus), 413 : native_widget_mus_(native_widget_mus),
413 show_state_(ui::mojom::ShowState::DEFAULT) { 414 show_state_(ui::mojom::ShowState::DEFAULT) {
414 mus_window()->AddObserver(this); 415 mus_window()->AddObserver(this);
415 } 416 }
416 417
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 (*properties)[ui::mojom::WindowManager::kWindowType_Property] = 686 (*properties)[ui::mojom::WindowManager::kWindowType_Property] =
686 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>( 687 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(
687 mojo::ConvertTo<ui::mojom::WindowType>(init_params.type))); 688 mojo::ConvertTo<ui::mojom::WindowType>(init_params.type)));
688 if (init_params.delegate && 689 if (init_params.delegate &&
689 properties->count(ui::mojom::WindowManager::kResizeBehavior_Property) == 690 properties->count(ui::mojom::WindowManager::kResizeBehavior_Property) ==
690 0) { 691 0) {
691 (*properties)[ui::mojom::WindowManager::kResizeBehavior_Property] = 692 (*properties)[ui::mojom::WindowManager::kResizeBehavior_Property] =
692 mojo::ConvertTo<std::vector<uint8_t>>( 693 mojo::ConvertTo<std::vector<uint8_t>>(
693 ResizeBehaviorFromDelegate(init_params.delegate)); 694 ResizeBehaviorFromDelegate(init_params.delegate));
694 } 695 }
695 SkBitmap app_icon = AppIconFromDelegate(init_params.delegate); 696
696 if (!app_icon.isNull()) { 697 if (init_params.delegate) {
697 (*properties)[ui::mojom::WindowManager::kWindowAppIcon_Property] = 698 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
698 mojo::ConvertTo<std::vector<uint8_t>>(app_icon); 699 gfx::ImageSkia app_icon = init_params.delegate->GetWindowAppIcon();
700 SkBitmap app_bitmap = app_icon.GetRepresentation(1.f).sk_bitmap();
701 if (!app_bitmap.isNull()) {
702 (*properties)[ui::mojom::WindowManager::kAppIcon_Property] =
703 mojo::ConvertTo<std::vector<uint8_t>>(app_bitmap);
704 }
705 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia].
706 gfx::ImageSkia window_icon = init_params.delegate->GetWindowIcon();
707 SkBitmap window_bitmap = window_icon.GetRepresentation(1.f).sk_bitmap();
708 if (!window_bitmap.isNull()) {
709 (*properties)[ui::mojom::WindowManager::kWindowIcon_Property] =
710 mojo::ConvertTo<std::vector<uint8_t>>(window_bitmap);
711 }
699 } 712 }
700 } 713 }
701 714
702 //////////////////////////////////////////////////////////////////////////////// 715 ////////////////////////////////////////////////////////////////////////////////
703 // NativeWidgetMus, internal::NativeWidgetPrivate implementation: 716 // NativeWidgetMus, internal::NativeWidgetPrivate implementation:
704 717
705 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { 718 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() {
706 return new ClientSideNonClientFrameView(GetWidget()); 719 return new ClientSideNonClientFrameView(GetWidget());
707 } 720 }
708 721
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 return false; 945 return false;
933 window_->SetSharedProperty<base::string16>(kWindowTitle_Property, title); 946 window_->SetSharedProperty<base::string16>(kWindowTitle_Property, title);
934 return true; 947 return true;
935 } 948 }
936 949
937 void NativeWidgetMus::SetWindowIcons(const gfx::ImageSkia& window_icon, 950 void NativeWidgetMus::SetWindowIcons(const gfx::ImageSkia& window_icon,
938 const gfx::ImageSkia& app_icon) { 951 const gfx::ImageSkia& app_icon) {
939 if (is_parallel_widget_in_window_manager()) 952 if (is_parallel_widget_in_window_manager())
940 return; 953 return;
941 954
942 const char* const kWindowAppIcon_Property = 955 SetIconProperty(window_, ui::mojom::WindowManager::kWindowIcon_Property,
943 ui::mojom::WindowManager::kWindowAppIcon_Property; 956 window_icon);
944 957 SetIconProperty(window_, ui::mojom::WindowManager::kAppIcon_Property,
945 if (!app_icon.isNull()) { 958 app_icon);
946 // Send the app icon 1x bitmap to the window manager.
947 // TODO(jamescook): Support other scale factors.
948 window_->SetSharedProperty<SkBitmap>(
949 kWindowAppIcon_Property, app_icon.GetRepresentation(1.f).sk_bitmap());
950 } else if (window_->HasSharedProperty(kWindowAppIcon_Property)) {
951 // Remove the existing icon.
952 window_->ClearSharedProperty(kWindowAppIcon_Property);
953 }
954 } 959 }
955 960
956 void NativeWidgetMus::InitModalType(ui::ModalType modal_type) { 961 void NativeWidgetMus::InitModalType(ui::ModalType modal_type) {
957 if (modal_type != ui::MODAL_TYPE_NONE) 962 if (modal_type != ui::MODAL_TYPE_NONE)
958 window_->SetModal(); 963 window_->SetModal();
959 } 964 }
960 965
961 gfx::Rect NativeWidgetMus::GetWindowBoundsInScreen() const { 966 gfx::Rect NativeWidgetMus::GetWindowBoundsInScreen() const {
962 if (!window_) 967 if (!window_)
963 return gfx::Rect(); 968 return gfx::Rect();
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 1575
1571 gfx::Path mask_path; 1576 gfx::Path mask_path;
1572 native_widget_delegate_->GetHitTestMask(&mask_path); 1577 native_widget_delegate_->GetHitTestMask(&mask_path);
1573 // TODO(jamescook): Use the full path for the mask. 1578 // TODO(jamescook): Use the full path for the mask.
1574 gfx::Rect mask_rect = 1579 gfx::Rect mask_rect =
1575 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds())); 1580 gfx::ToEnclosingRect(gfx::SkRectToRectF(mask_path.getBounds()));
1576 window_->SetHitTestMask(mask_rect); 1581 window_->SetHitTestMask(mask_rect);
1577 } 1582 }
1578 1583
1579 } // namespace views 1584 } // namespace views
OLDNEW
« no previous file with comments | « ui/aura/mus/property_converter_unittest.cc ('k') | ui/views/mus/native_widget_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698