Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "ios/chrome/browser/ui/uikit_ui_util.h" | 5 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 6 | 6 |
| 7 #import <Accelerate/Accelerate.h> | 7 #import <Accelerate/Accelerate.h> |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 #import <QuartzCore/QuartzCore.h> | 9 #import <QuartzCore/QuartzCore.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 UIImage* result = [UIImage imageWithCGImage:cgImage]; | 447 UIImage* result = [UIImage imageWithCGImage:cgImage]; |
| 448 CGImageRelease(cgImage); | 448 CGImageRelease(cgImage); |
| 449 return result; | 449 return result; |
| 450 } | 450 } |
| 451 | 451 |
| 452 UIInterfaceOrientation GetInterfaceOrientation() { | 452 UIInterfaceOrientation GetInterfaceOrientation() { |
| 453 return [[UIApplication sharedApplication] statusBarOrientation]; | 453 return [[UIApplication sharedApplication] statusBarOrientation]; |
| 454 } | 454 } |
| 455 | 455 |
| 456 CGFloat CurrentKeyboardHeight(NSValue* keyboardFrameValue) { | 456 CGFloat CurrentKeyboardHeight(NSValue* keyboardFrameValue) { |
| 457 CGSize keyboardSize = [keyboardFrameValue CGRectValue].size; | 457 CGSize keyboardSize = [keyboardFrameValue CGRectValue].size; |
|
justincohen
2016/10/18 10:59:20
return [keyboardFrameValue CGRectValue].size.heigh
pkl (ping after 24h if needed)
2016/10/19 18:47:32
Done.
| |
| 458 if (base::ios::IsRunningOnIOS8OrLater()) { | 458 return keyboardSize.height; |
| 459 return keyboardSize.height; | |
| 460 } else { | |
| 461 return IsPortrait() ? keyboardSize.height : keyboardSize.width; | |
| 462 } | |
| 463 } | 459 } |
| 464 | 460 |
| 465 UIImage* ImageWithColor(UIColor* color) { | 461 UIImage* ImageWithColor(UIColor* color) { |
| 466 CGRect rect = CGRectMake(0, 0, 1, 1); | 462 CGRect rect = CGRectMake(0, 0, 1, 1); |
| 467 UIGraphicsBeginImageContext(rect.size); | 463 UIGraphicsBeginImageContext(rect.size); |
| 468 CGContextRef context = UIGraphicsGetCurrentContext(); | 464 CGContextRef context = UIGraphicsGetCurrentContext(); |
| 469 CGContextSetFillColorWithColor(context, [color CGColor]); | 465 CGContextSetFillColorWithColor(context, [color CGColor]); |
| 470 CGContextFillRect(context, rect); | 466 CGContextFillRect(context, rect); |
| 471 UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); | 467 UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); |
| 472 UIGraphicsEndImageContext(); | 468 UIGraphicsEndImageContext(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 611 void AddSameSizeConstraint(UIView* view1, UIView* view2) { | 607 void AddSameSizeConstraint(UIView* view1, UIView* view2) { |
| 612 [NSLayoutConstraint activateConstraints:@[ | 608 [NSLayoutConstraint activateConstraints:@[ |
| 613 [view1.leadingAnchor constraintEqualToAnchor:view2.leadingAnchor], | 609 [view1.leadingAnchor constraintEqualToAnchor:view2.leadingAnchor], |
| 614 [view1.trailingAnchor constraintEqualToAnchor:view2.trailingAnchor], | 610 [view1.trailingAnchor constraintEqualToAnchor:view2.trailingAnchor], |
| 615 [view1.topAnchor constraintEqualToAnchor:view2.topAnchor], | 611 [view1.topAnchor constraintEqualToAnchor:view2.topAnchor], |
| 616 [view1.bottomAnchor constraintEqualToAnchor:view2.bottomAnchor] | 612 [view1.bottomAnchor constraintEqualToAnchor:view2.bottomAnchor] |
| 617 ]]; | 613 ]]; |
| 618 } | 614 } |
| 619 | 615 |
| 620 bool IsCompact(id<UITraitEnvironment> environment) { | 616 bool IsCompact(id<UITraitEnvironment> environment) { |
| 621 if (base::ios::IsRunningOnIOS8OrLater()) { | 617 return environment.traitCollection.horizontalSizeClass == |
| 622 return environment.traitCollection.horizontalSizeClass == | 618 UIUserInterfaceSizeClassCompact; |
| 623 UIUserInterfaceSizeClassCompact; | |
| 624 } else { | |
| 625 // Prior to iOS 8, iPad is always regular, iPhone is always compact. | |
| 626 return !IsIPadIdiom(); | |
| 627 } | |
| 628 } | 619 } |
| 629 | 620 |
| 630 bool IsCompact() { | 621 bool IsCompact() { |
| 631 UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow; | 622 UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow; |
| 632 return IsCompact(keyWindow); | 623 return IsCompact(keyWindow); |
| 633 } | 624 } |
| 634 | 625 |
| 635 bool IsCompactTablet(id<UITraitEnvironment> environment) { | 626 bool IsCompactTablet(id<UITraitEnvironment> environment) { |
| 636 return IsIPadIdiom() && IsCompact(environment); | 627 return IsIPadIdiom() && IsCompact(environment); |
| 637 } | 628 } |
| 638 | 629 |
| 639 bool IsCompactTablet() { | 630 bool IsCompactTablet() { |
| 640 return IsIPadIdiom() && IsCompact(); | 631 return IsIPadIdiom() && IsCompact(); |
| 641 } | 632 } |
| 642 | 633 |
| 643 // Returns the current first responder. | 634 // Returns the current first responder. |
| 644 UIResponder* GetFirstResponder() { | 635 UIResponder* GetFirstResponder() { |
| 645 DCHECK_CURRENTLY_ON(web::WebThread::UI); | 636 DCHECK_CURRENTLY_ON(web::WebThread::UI); |
| 646 DCHECK(!gFirstResponder); | 637 DCHECK(!gFirstResponder); |
| 647 [[UIApplication sharedApplication] | 638 [[UIApplication sharedApplication] |
| 648 sendAction:@selector(cr_markSelfCurrentFirstResponder) | 639 sendAction:@selector(cr_markSelfCurrentFirstResponder) |
| 649 to:nil | 640 to:nil |
| 650 from:nil | 641 from:nil |
| 651 forEvent:nil]; | 642 forEvent:nil]; |
| 652 UIResponder* firstResponder = gFirstResponder; | 643 UIResponder* firstResponder = gFirstResponder; |
| 653 gFirstResponder = nil; | 644 gFirstResponder = nil; |
| 654 return firstResponder; | 645 return firstResponder; |
| 655 } | 646 } |
| OLD | NEW |