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

Side by Side Diff: ui/arc/notification/arc_custom_notification_view.cc

Issue 2187363002: arc: Scale notification surface to fit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix floating close button pos on 2560x1700 by using coordinate before scaling Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/arc/notification/arc_custom_notification_view.h" 5 #include "ui/arc/notification/arc_custom_notification_view.h"
6 6
7 #include "components/exo/notification_surface.h" 7 #include "components/exo/notification_surface.h"
8 #include "components/exo/surface.h" 8 #include "components/exo/surface.h"
9 #include "third_party/skia/include/core/SkColor.h" 9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/message_center/message_center_style.h"
12 #include "ui/resources/grit/ui_resources.h" 13 #include "ui/resources/grit/ui_resources.h"
13 #include "ui/strings/grit/ui_strings.h" 14 #include "ui/strings/grit/ui_strings.h"
14 #include "ui/views/background.h" 15 #include "ui/views/background.h"
15 #include "ui/views/border.h" 16 #include "ui/views/border.h"
16 #include "ui/views/controls/button/image_button.h" 17 #include "ui/views/controls/button/image_button.h"
17 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
18 19
19 namespace arc { 20 namespace arc {
20 21
21 ArcCustomNotificationView::ArcCustomNotificationView( 22 ArcCustomNotificationView::ArcCustomNotificationView(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 if (widget && native_view() && 74 if (widget && native_view() &&
74 views::Widget::GetTopLevelWidgetForNativeView(native_view()) != widget) { 75 views::Widget::GetTopLevelWidgetForNativeView(native_view()) != widget) {
75 return; 76 return;
76 } 77 }
77 78
78 views::NativeViewHost::ViewHierarchyChanged(details); 79 views::NativeViewHost::ViewHierarchyChanged(details);
79 80
80 if (!widget || !surface_ || !details.is_add) 81 if (!widget || !surface_ || !details.is_add)
81 return; 82 return;
82 83
83 SetPreferredSize(surface_->GetSize()); 84 gfx::Size preferred_size = surface_->GetSize();
85 float scale = 1.0f;
86 if (preferred_size.width() != message_center::kNotificationWidth) {
87 scale = static_cast<float>(message_center::kNotificationWidth) /
88 preferred_size.width();
89 preferred_size.SetSize(message_center::kNotificationWidth,
90 preferred_size.height() * scale);
91 }
92
93 SetPreferredSize(preferred_size);
84 Attach(surface_->window()); 94 Attach(surface_->window());
85 } 95 }
86 96
87 void ArcCustomNotificationView::Layout() { 97 void ArcCustomNotificationView::Layout() {
88 views::NativeViewHost::Layout(); 98 views::NativeViewHost::Layout();
89 99
100 if (surface_) {
101 // Scale notification surface if necessary.
102 gfx::Transform transform;
103 const gfx::Size surface_size = surface_->GetSize();
104 const gfx::Size contents_size = GetContentsBounds().size();
105 if (!surface_size.IsEmpty() && !contents_size.IsEmpty() &&
106 surface_size != contents_size) {
reveman 2016/07/28 18:50:53 nit: "surface_size != contents_size" check is not
xiyuan 2016/07/28 19:32:51 Done.
107 transform.Scale(
108 static_cast<float>(contents_size.width()) / surface_size.width(),
109 static_cast<float>(contents_size.height()) / surface_size.height());
110 }
111 surface_->window()->SetTransform(transform);
112 }
113
90 if (!floating_close_button_widget_ || !surface_ || !GetWidget()) 114 if (!floating_close_button_widget_ || !surface_ || !GetWidget())
91 return; 115 return;
92 116
93 gfx::Rect surface_local_bounds(surface_->window()->bounds().size()); 117 gfx::Rect surface_local_bounds(surface_->GetSize());
94 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize()); 118 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize());
95 close_button_bounds.set_x(surface_local_bounds.right() - 119 close_button_bounds.set_x(surface_local_bounds.right() -
96 close_button_bounds.width()); 120 close_button_bounds.width());
97 close_button_bounds.set_y(surface_local_bounds.y()); 121 close_button_bounds.set_y(surface_local_bounds.y());
98 floating_close_button_widget_->SetBounds(close_button_bounds); 122 floating_close_button_widget_->SetBounds(close_button_bounds);
99 } 123 }
100 124
101 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, 125 void ArcCustomNotificationView::ButtonPressed(views::Button* sender,
102 const ui::Event& event) { 126 const ui::Event& event) {
103 if (item_ && !item_->pinned() && sender == floating_close_button_) { 127 if (item_ && !item_->pinned() && sender == floating_close_button_) {
(...skipping 16 matching lines...) Expand all
120 } else if (!item_->pinned() && !floating_close_button_widget_) { 144 } else if (!item_->pinned() && !floating_close_button_widget_) {
121 CreateFloatingCloseButton(); 145 CreateFloatingCloseButton();
122 } 146 }
123 } 147 }
124 148
125 void ArcCustomNotificationView::OnItemNotificationSurfaceRemoved() { 149 void ArcCustomNotificationView::OnItemNotificationSurfaceRemoved() {
126 surface_ = nullptr; 150 surface_ = nullptr;
127 } 151 }
128 152
129 } // namespace arc 153 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698