Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Add convenience methods for checking horizontal size class.
Browse files Browse the repository at this point in the history
This CL adds methods to check for horizontal size class of views, view
controllers, etc.

BUG=527404
R=justincohen@chromium.org,rohitrao@chromium.org

Review URL: https://codereview.chromium.org/1329713002

Cr-Commit-Position: refs/heads/master@{#347211}
(cherry picked from commit ab73901)

TBR=justincohen@chromium.org,rohitrao@chromium.org
NOTRY=true
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1321533006

Cr-Commit-Position: refs/branch-heads/2490@{#160}
Cr-Branched-From: 7790a35-refs/heads/master@{#344925}
  • Loading branch information
Arcank authored and Commit bot committed Sep 4, 2015
1 parent aa88a4d commit a2e65bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ios/chrome/browser/ui/uikit_ui_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,16 @@ void AddSameCenterYConstraint(UIView* parentView,
UIView* subview1,
UIView* subview2);

// Whether the |environment| has a compact horizontal size class.
bool IsCompact(id<UITraitEnvironment> environment);

// Whether the main application window's rootViewController has a compact
// horizontal size class.
bool IsCompact();

// Whether the |environment| has a compact iPad horizontal size class.
bool IsCompactTablet(id<UITraitEnvironment> environment);

// Whether the main application window's rootViewController has a compact
// iPad horizontal size class.
bool IsCompactTablet();
Expand Down
14 changes: 11 additions & 3 deletions ios/chrome/browser/ui/uikit_ui_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -517,17 +517,25 @@ void AddSameCenterYConstraint(UIView* parentView,
constant:0]];
}

bool IsCompact() {
bool IsCompact(id<UITraitEnvironment> environment) {
if (base::ios::IsRunningOnIOS8OrLater()) {
UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
return [keyWindow.traitCollection horizontalSizeClass] ==
return environment.traitCollection.horizontalSizeClass ==
UIUserInterfaceSizeClassCompact;
} else {
// Prior to iOS 8, iPad is always regular, iPhone is always compact.
return !IsIPadIdiom();
}
}

bool IsCompact() {
UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
return IsCompact(keyWindow);
}

bool IsCompactTablet(id<UITraitEnvironment> environment) {
return IsIPadIdiom() && IsCompact(environment);
}

bool IsCompactTablet() {
return IsIPadIdiom() && IsCompact();
}

0 comments on commit a2e65bc

Please sign in to comment.