Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ui/views/cocoa/bridged_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 [window_ invalidateShadow]; | 76 [window_ invalidateShadow]; |
| 77 } | 77 } |
| 78 - (void)setCurrentProgress:(NSAnimationProgress)progress { | 78 - (void)setCurrentProgress:(NSAnimationProgress)progress { |
| 79 [super setCurrentProgress:progress]; | 79 [super setCurrentProgress:progress]; |
| 80 [window_ invalidateShadow]; | 80 [window_ invalidateShadow]; |
| 81 } | 81 } |
| 82 @end | 82 @end |
| 83 | 83 |
| 84 namespace { | 84 namespace { |
| 85 | 85 |
| 86 using RankMap = std::map<NSView*, int>; | |
| 87 | |
| 86 const CGFloat kMavericksMenuOpacity = 251.0 / 255.0; | 88 const CGFloat kMavericksMenuOpacity = 251.0 / 255.0; |
| 87 const CGFloat kYosemiteMenuOpacity = 194.0 / 255.0; | 89 const CGFloat kYosemiteMenuOpacity = 194.0 / 255.0; |
| 88 const int kYosemiteMenuBlur = 80; | 90 const int kYosemiteMenuBlur = 80; |
| 89 | 91 |
| 90 // Margin at edge and corners of the window that trigger resizing. These match | 92 // Margin at edge and corners of the window that trigger resizing. These match |
| 91 // actual Cocoa resize margins. | 93 // actual Cocoa resize margins. |
| 92 const int kResizeAreaEdgeSize = 3; | 94 const int kResizeAreaEdgeSize = 3; |
| 93 const int kResizeAreaCornerSize = 12; | 95 const int kResizeAreaCornerSize = 12; |
| 94 | 96 |
| 95 int kWindowPropertiesKey; | 97 int kWindowPropertiesKey; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 // resize operations to coordinate with frames provided by the GPU process. | 258 // resize operations to coordinate with frames provided by the GPU process. |
| 257 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() { | 259 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner() { |
| 258 // If the WindowResizeHelper's pumpable task runner is set, it means the GPU | 260 // If the WindowResizeHelper's pumpable task runner is set, it means the GPU |
| 259 // process is directing messages there, and the compositor can synchronize | 261 // process is directing messages there, and the compositor can synchronize |
| 260 // with it. Otherwise, just use the UI thread. | 262 // with it. Otherwise, just use the UI thread. |
| 261 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 263 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 262 ui::WindowResizeHelperMac::Get()->task_runner(); | 264 ui::WindowResizeHelperMac::Get()->task_runner(); |
| 263 return task_runner ? task_runner : base::ThreadTaskRunnerHandle::Get(); | 265 return task_runner ? task_runner : base::ThreadTaskRunnerHandle::Get(); |
| 264 } | 266 } |
| 265 | 267 |
| 268 void RankNSViews(views::View* view, | |
| 269 const views::BridgedNativeWidget::AssociatedViews& hosts, | |
| 270 RankMap* rank) { | |
| 271 auto it = hosts.find(view); | |
| 272 if (it != hosts.end()) | |
| 273 rank->emplace(it->second, rank->size()); | |
| 274 for (int i = 0; i < view->child_count(); ++i) | |
| 275 RankNSViews(view->child_at(i), hosts, rank); | |
| 276 } | |
| 277 | |
| 278 NSComparisonResult SubviewSorter(id lhs, id rhs, void* rank_as_void) { | |
|
tapted
2016/03/17 23:51:27
Make sure you do a build with xcode 7 too. I had t
| |
| 279 DCHECK_NE(lhs, rhs); | |
| 280 | |
| 281 const RankMap* rank = static_cast<const RankMap*>(rank_as_void); | |
| 282 auto left_rank = rank->find(lhs); | |
| 283 auto right_rank = rank->find(rhs); | |
| 284 bool left_found = left_rank != rank->end(); | |
| 285 bool right_found = right_rank != rank->end(); | |
| 286 | |
| 287 // Sort unassociated views above associated views. | |
| 288 if (left_found != right_found) | |
| 289 return left_found ? NSOrderedAscending : NSOrderedDescending; | |
| 290 | |
| 291 if (left_found) { | |
| 292 return left_rank->second < right_rank->second ? NSOrderedAscending | |
| 293 : NSOrderedDescending; | |
| 294 } | |
| 295 | |
| 296 // If both are unassociated, consider that order is not important | |
| 297 return NSOrderedSame; | |
| 298 } | |
| 299 | |
| 266 } // namespace | 300 } // namespace |
| 267 | 301 |
| 268 namespace views { | 302 namespace views { |
| 269 | 303 |
| 270 // static | 304 // static |
| 271 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize( | 305 gfx::Size BridgedNativeWidget::GetWindowSizeForClientSize( |
| 272 NSWindow* window, | 306 NSWindow* window, |
| 273 const gfx::Size& content_size) { | 307 const gfx::Size& content_size) { |
| 274 NSRect content_rect = | 308 NSRect content_rect = |
| 275 NSMakeRect(0, 0, content_size.width(), content_size.height()); | 309 NSMakeRect(0, 0, content_size.width(), content_size.height()); |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 877 // to generate a window shadow from the composited CALayer. To get around | 911 // to generate a window shadow from the composited CALayer. To get around |
| 878 // this, let the window background remain opaque and clip the window | 912 // this, let the window background remain opaque and clip the window |
| 879 // boundary in drawRect method of BridgedContentView. See crbug.com/543671. | 913 // boundary in drawRect method of BridgedContentView. See crbug.com/543671. |
| 880 if (base::mac::IsOSYosemiteOrLater()) | 914 if (base::mac::IsOSYosemiteOrLater()) |
| 881 [window_ setBackgroundColor:[NSColor clearColor]]; | 915 [window_ setBackgroundColor:[NSColor clearColor]]; |
| 882 } | 916 } |
| 883 | 917 |
| 884 UpdateLayerProperties(); | 918 UpdateLayerProperties(); |
| 885 } | 919 } |
| 886 | 920 |
| 921 void BridgedNativeWidget::SetAssociationForView(const views::View* view, | |
| 922 NSView* native_view) { | |
| 923 DCHECK_EQ(0u, associated_views_.count(view)); | |
| 924 associated_views_[view] = native_view; | |
| 925 native_widget_mac_->GetWidget()->ReorderNativeViews(); | |
| 926 } | |
| 927 | |
| 928 void BridgedNativeWidget::ClearAssociationForView(const views::View* view) { | |
| 929 auto it = associated_views_.find(view); | |
| 930 DCHECK(it != associated_views_.end()); | |
| 931 associated_views_.erase(it); | |
| 932 } | |
| 933 | |
| 934 void BridgedNativeWidget::ReorderChildViews() { | |
| 935 RankMap rank; | |
| 936 Widget* widget = native_widget_mac_->GetWidget(); | |
| 937 RankNSViews(widget->GetRootView(), associated_views_, &rank); | |
| 938 // Set compositor view below | |
|
tapted
2016/03/17 23:04:15
Yep - this makes sense, but the comment should exp
| |
| 939 if (compositor_superview_) | |
| 940 rank[compositor_superview_.get()] = -1; | |
|
tapted
2016/03/17 23:04:15
The .get() shouldn't be required -- scoped_nsobjec
| |
| 941 [widget->GetNativeView() sortSubviewsUsingFunction:&SubviewSorter | |
|
tapted
2016/03/17 23:04:15
widget->GetNativeView() --> bridged_view_
| |
| 942 context:&rank]; | |
| 943 } | |
| 944 | |
| 887 //////////////////////////////////////////////////////////////////////////////// | 945 //////////////////////////////////////////////////////////////////////////////// |
| 888 // BridgedNativeWidget, internal::InputMethodDelegate: | 946 // BridgedNativeWidget, internal::InputMethodDelegate: |
| 889 | 947 |
| 890 ui::EventDispatchDetails BridgedNativeWidget::DispatchKeyEventPostIME( | 948 ui::EventDispatchDetails BridgedNativeWidget::DispatchKeyEventPostIME( |
| 891 ui::KeyEvent* key) { | 949 ui::KeyEvent* key) { |
| 892 DCHECK(focus_manager_); | 950 DCHECK(focus_manager_); |
| 893 native_widget_mac_->GetWidget()->OnKeyEvent(key); | 951 native_widget_mac_->GetWidget()->OnKeyEvent(key); |
| 894 if (!key->handled()) { | 952 if (!key->handled()) { |
| 895 if (!focus_manager_->OnKeyEvent(*key)) | 953 if (!focus_manager_->OnKeyEvent(*key)) |
| 896 key->StopPropagation(); | 954 key->StopPropagation(); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1238 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1296 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
| 1239 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1297 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
| 1240 // changes. Previously we tried adding an NSView and removing it, but for some | 1298 // changes. Previously we tried adding an NSView and removing it, but for some |
| 1241 // reason it required reposting the mouse-down event, and didn't always work. | 1299 // reason it required reposting the mouse-down event, and didn't always work. |
| 1242 // Calling the below seems to be an effective solution. | 1300 // Calling the below seems to be an effective solution. |
| 1243 [window_ setMovableByWindowBackground:NO]; | 1301 [window_ setMovableByWindowBackground:NO]; |
| 1244 [window_ setMovableByWindowBackground:YES]; | 1302 [window_ setMovableByWindowBackground:YES]; |
| 1245 } | 1303 } |
| 1246 | 1304 |
| 1247 } // namespace views | 1305 } // namespace views |
| OLD | NEW |