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_content_view.h" | 5 #import "ui/views/cocoa/bridged_content_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "base/mac/mac_util.h" | 8 #import "base/mac/mac_util.h" |
| 9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
| 10 #import "base/mac/sdk_forward_declarations.h" | 10 #import "base/mac/sdk_forward_declarations.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #include "skia/ext/skia_utils_mac.h" | 12 #include "skia/ext/skia_utils_mac.h" |
| 13 #include "ui/base/cocoa/cocoa_base_utils.h" | 13 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 14 #include "ui/base/dragdrop/drag_drop_types.h" | 14 #include "ui/base/dragdrop/drag_drop_types.h" |
| 15 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" | 15 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
| 16 #include "ui/base/ime/input_method.h" | 16 #include "ui/base/ime/input_method.h" |
| 17 #include "ui/base/ime/text_edit_commands.h" | 17 #include "ui/base/ime/text_edit_commands.h" |
| 18 #include "ui/base/ime/text_input_client.h" | 18 #include "ui/base/ime/text_input_client.h" |
| 19 #include "ui/base/models/dialog_model.h" | |
| 19 #include "ui/compositor/canvas_painter.h" | 20 #include "ui/compositor/canvas_painter.h" |
| 20 #import "ui/events/cocoa/cocoa_event_utils.h" | 21 #import "ui/events/cocoa/cocoa_event_utils.h" |
| 21 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
| 22 #include "ui/events/keycodes/dom/dom_code.h" | 23 #include "ui/events/keycodes/dom/dom_code.h" |
| 23 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 24 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
| 24 #include "ui/gfx/canvas_paint_mac.h" | 25 #include "ui/gfx/canvas_paint_mac.h" |
| 25 #include "ui/gfx/decorated_text.h" | 26 #include "ui/gfx/decorated_text.h" |
| 26 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
| 27 #import "ui/gfx/mac/coordinate_conversion.h" | 28 #import "ui/gfx/mac/coordinate_conversion.h" |
| 28 #include "ui/gfx/path.h" | 29 #include "ui/gfx/path.h" |
| 29 #import "ui/gfx/path_mac.h" | 30 #import "ui/gfx/path_mac.h" |
| 30 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 31 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 31 #import "ui/views/cocoa/bridged_native_widget.h" | 32 #import "ui/views/cocoa/bridged_native_widget.h" |
| 32 #import "ui/views/cocoa/drag_drop_client_mac.h" | 33 #import "ui/views/cocoa/drag_drop_client_mac.h" |
| 33 #include "ui/views/controls/menu/menu_config.h" | 34 #include "ui/views/controls/menu/menu_config.h" |
| 34 #include "ui/views/controls/menu/menu_controller.h" | 35 #include "ui/views/controls/menu/menu_controller.h" |
| 35 #include "ui/views/view.h" | 36 #include "ui/views/view.h" |
| 36 #include "ui/views/widget/native_widget_mac.h" | 37 #include "ui/views/widget/native_widget_mac.h" |
| 37 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 39 #include "ui/views/widget/widget_delegate.h" | |
| 40 #include "ui/views/window/dialog_delegate.h" | |
| 38 #include "ui/views/word_lookup_client.h" | 41 #include "ui/views/word_lookup_client.h" |
| 39 | 42 |
| 40 using views::MenuController; | 43 using views::MenuController; |
| 41 | 44 |
| 45 @interface NSButton (SierraAPI) | |
| 46 @property(nullable, copy) NSColor* bezelColor; | |
| 47 + (instancetype)buttonWithTitle:(NSString*)title | |
| 48 target:(id)target | |
| 49 action:(SEL)action; | |
| 50 @end | |
| 51 | |
| 52 #if !defined(MAC_OS_X_VERSION_10_12_1) | |
| 53 | |
| 54 typedef NSObject NSTouchBar; | |
| 55 typedef NSObject NSTouchBarItem; | |
| 56 typedef NSObject NSCustomTouchBarItem; | |
| 57 typedef NSObject NSGroupTouchBarItem; | |
| 58 typedef NSString* NSTouchBarItemIdentifier; | |
| 59 | |
| 60 @interface NSObject (FakeNSTouchBar) | |
| 61 @property(copy) NSArray* defaultItemIdentifiers; | |
| 62 @property(copy, nullable) NSTouchBarItemIdentifier principalItemIdentifier; | |
| 63 @property(nullable, weak) id<NSTouchBarDelegate> delegate; | |
| 64 @end | |
| 65 | |
| 66 @interface NSObject (FakeNSGroupTouchBarItem) | |
| 67 + (NSGroupTouchBarItem*)groupItemWithIdentifier: | |
| 68 (NSTouchBarItemIdentifier)identifier | |
| 69 items:(NSArray*)items; | |
| 70 @end | |
| 71 | |
| 72 @interface NSObject (FakeNSCustomTouchBarItem) | |
| 73 @property(readwrite, strong) NSView* view; | |
| 74 @end | |
| 75 | |
| 76 #else | |
| 77 | |
| 78 @class NSTouchBar; | |
| 79 @class NSTouchBarItem; | |
| 80 @class NSCustomTouchBarItem; | |
| 81 @class NSGroupTouchBarItem; | |
| 82 | |
| 83 #endif | |
| 84 | |
| 42 namespace { | 85 namespace { |
| 43 | 86 |
| 44 NSString* const kFullKeyboardAccessChangedNotification = | 87 NSString* const kFullKeyboardAccessChangedNotification = |
| 45 @"com.apple.KeyboardUIModeDidChange"; | 88 @"com.apple.KeyboardUIModeDidChange"; |
| 89 NSString* const kTouchBarDialogButtonsGroupId = | |
| 90 @"com.google.chrome-DIALOG-BUTTONS-GROUP"; | |
| 91 NSString* const kTouchBarOKId = @"com.google.chrome-OK"; | |
| 92 NSString* const kTouchBarCancelId = @"com.google.chrome-CANCEL"; | |
| 46 | 93 |
| 47 // Returns true if all four corners of |rect| are contained inside |path|. | 94 // Returns true if all four corners of |rect| are contained inside |path|. |
| 48 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { | 95 bool IsRectInsidePath(NSRect rect, NSBezierPath* path) { |
| 49 return [path containsPoint:rect.origin] && | 96 return [path containsPoint:rect.origin] && |
| 50 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 97 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 51 rect.origin.y)] && | 98 rect.origin.y)] && |
| 52 [path containsPoint:NSMakePoint(rect.origin.x, | 99 [path containsPoint:NSMakePoint(rect.origin.x, |
| 53 rect.origin.y + rect.size.height)] && | 100 rect.origin.y + rect.size.height)] && |
| 54 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, | 101 [path containsPoint:NSMakePoint(rect.origin.x + rect.size.width, |
| 55 rect.origin.y + rect.size.height)]; | 102 rect.origin.y + rect.size.height)]; |
| (...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1411 } | 1458 } |
| 1412 | 1459 |
| 1413 - (void)draggingSession:(NSDraggingSession*)session | 1460 - (void)draggingSession:(NSDraggingSession*)session |
| 1414 endedAtPoint:(NSPoint)screenPoint | 1461 endedAtPoint:(NSPoint)screenPoint |
| 1415 operation:(NSDragOperation)operation { | 1462 operation:(NSDragOperation)operation { |
| 1416 views::DragDropClientMac* client = [self dragDropClient]; | 1463 views::DragDropClientMac* client = [self dragDropClient]; |
| 1417 if (client) | 1464 if (client) |
| 1418 client->EndDrag(); | 1465 client->EndDrag(); |
| 1419 } | 1466 } |
| 1420 | 1467 |
| 1468 // TouchBar action. | |
| 1469 | |
| 1470 - (void)touchBarButtonAction:(id)sender { | |
| 1471 if (!hostedView_) | |
| 1472 return; | |
| 1473 | |
| 1474 views::DialogDelegate* dialog = | |
| 1475 hostedView_->GetWidget()->widget_delegate()->AsDialogDelegate(); | |
| 1476 DCHECK(dialog); | |
| 1477 | |
| 1478 if ([sender tag] == ui::DIALOG_BUTTON_OK) { | |
| 1479 dialog->Accept(); | |
| 1480 return; | |
| 1481 } | |
| 1482 | |
| 1483 DCHECK_EQ([sender tag], ui::DIALOG_BUTTON_CANCEL); | |
| 1484 dialog->Cancel(); | |
| 1485 } | |
| 1486 | |
| 1487 // NSTouchBarDelegate protocol implementation. | |
| 1488 | |
| 1489 - (NSTouchBarItem*)touchBar:(NSTouchBar*)touchBar | |
| 1490 makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { | |
| 1491 if (!hostedView_) | |
| 1492 return nil; | |
| 1493 | |
| 1494 if ([identifier isEqualToString:kTouchBarDialogButtonsGroupId]) { | |
| 1495 NSMutableArray* items = [NSMutableArray arrayWithCapacity:2]; | |
| 1496 for (NSTouchBarItemIdentifier i : @[ kTouchBarCancelId, kTouchBarOKId ]) { | |
| 1497 NSTouchBarItem* item = [self touchBar:touchBar makeItemForIdentifier:i]; | |
| 1498 if (item) | |
| 1499 [items addObject:item]; | |
| 1500 } | |
| 1501 if ([items count] == 0) | |
| 1502 return nil; | |
| 1503 return [NSGroupTouchBarItem groupItemWithIdentifier:identifier items:items]; | |
| 1504 } | |
| 1505 | |
| 1506 ui::DialogButton type = ui::DIALOG_BUTTON_NONE; | |
| 1507 if ([identifier isEqualToString:kTouchBarOKId]) | |
| 1508 type = ui::DIALOG_BUTTON_OK; | |
| 1509 else if ([identifier isEqualToString:kTouchBarCancelId]) | |
| 1510 type = ui::DIALOG_BUTTON_CANCEL; | |
| 1511 else | |
| 1512 return nil; | |
| 1513 | |
| 1514 ui::DialogModel* model = | |
| 1515 hostedView_->GetWidget()->widget_delegate()->AsDialogDelegate(); | |
| 1516 if (!model || !(model->GetDialogButtons() & type)) | |
| 1517 return nil; | |
| 1518 | |
| 1519 base::scoped_nsobject<NSCustomTouchBarItem> item([[NSClassFromString( | |
| 1520 @"NSCustomTouchBarItem") alloc] initWithIdentifier:identifier]); | |
| 1521 NSString* title = base::SysUTF16ToNSString(model->GetDialogButtonLabel(type)); | |
| 1522 NSButton* button = | |
| 1523 [NSButton buttonWithTitle:title | |
| 1524 target:self | |
| 1525 action:@selector(touchBarButtonAction:)]; | |
| 1526 if (type == model->GetDefaultDialogButton()) { | |
| 1527 [button setKeyEquivalent:@"\n"]; | |
|
tapted
2016/11/02 09:28:57
I'd hoped this would give the blue color, but actu
Avi (use Gerrit)
2016/11/02 14:50:41
Can we hopper up NSAlert and see what it's doing t
tapted
2016/11/03 04:36:29
Dumped my findings to http://crbug.com/661581 - it
| |
| 1528 [button setBezelColor:[NSColor colorWithSRGBRed:0.168 | |
| 1529 green:0.51 | |
| 1530 blue:0.843 | |
| 1531 alpha:1.0]]; | |
| 1532 } | |
| 1533 [button setEnabled:model->IsDialogButtonEnabled(type)]; | |
| 1534 [button setTag:type]; | |
| 1535 [item setView:button]; | |
| 1536 return item.autorelease(); | |
| 1537 } | |
| 1538 | |
| 1539 // NSTouchBarProvider protocol implementation (via NSResonder category). | |
| 1540 | |
| 1541 - (NSTouchBar*)makeTouchBar { | |
| 1542 if (!hostedView_) | |
| 1543 return nil; | |
| 1544 | |
| 1545 ui::DialogModel* model = | |
| 1546 hostedView_->GetWidget()->widget_delegate()->AsDialogDelegate(); | |
| 1547 if (!model || !model->GetDialogButtons()) | |
| 1548 return nil; | |
| 1549 | |
| 1550 base::scoped_nsobject<NSTouchBar> bar( | |
| 1551 [[NSClassFromString(@"NSTouchBar") alloc] init]); | |
| 1552 [bar setDelegate:self]; | |
| 1553 [bar setDefaultItemIdentifiers:@[ kTouchBarDialogButtonsGroupId ]]; | |
| 1554 [bar setPrincipalItemIdentifier:kTouchBarDialogButtonsGroupId]; | |
| 1555 return bar.autorelease(); | |
| 1556 } | |
| 1557 | |
| 1421 // NSAccessibility informal protocol implementation. | 1558 // NSAccessibility informal protocol implementation. |
| 1422 | 1559 |
| 1423 - (id)accessibilityAttributeValue:(NSString*)attribute { | 1560 - (id)accessibilityAttributeValue:(NSString*)attribute { |
| 1424 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) { | 1561 if ([attribute isEqualToString:NSAccessibilityChildrenAttribute]) { |
| 1425 return @[ hostedView_->GetNativeViewAccessible() ]; | 1562 return @[ hostedView_->GetNativeViewAccessible() ]; |
| 1426 } | 1563 } |
| 1427 | 1564 |
| 1428 return [super accessibilityAttributeValue:attribute]; | 1565 return [super accessibilityAttributeValue:attribute]; |
| 1429 } | 1566 } |
| 1430 | 1567 |
| 1431 - (id)accessibilityHitTest:(NSPoint)point { | 1568 - (id)accessibilityHitTest:(NSPoint)point { |
| 1432 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1569 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 1433 } | 1570 } |
| 1434 | 1571 |
| 1435 - (id)accessibilityFocusedUIElement { | 1572 - (id)accessibilityFocusedUIElement { |
| 1436 if (!hostedView_) | 1573 if (!hostedView_) |
| 1437 return nil; | 1574 return nil; |
| 1438 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; | 1575 return [hostedView_->GetNativeViewAccessible() accessibilityFocusedUIElement]; |
| 1439 } | 1576 } |
| 1440 | 1577 |
| 1441 @end | 1578 @end |
| OLD | NEW |