Merge pull request #2250 from EyeSee360/master

Maintain an aspect ratio for content within a window
This commit is contained in:
Cheng Zhao 2015-07-23 09:45:42 +08:00
commit ea1b89c699
6 changed files with 66 additions and 0 deletions

View file

@ -95,6 +95,33 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
shell_->NotifyWindowBlur();
}
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize {
NSSize newSize = frameSize;
double aspectRatio = shell_->GetAspectRatio();
if (aspectRatio > 0.0) {
gfx::Size windowFrameSize = shell_->GetSize();
gfx::Size contentViewSize = shell_->GetContentSize();
gfx::Size aspectRatioExtraSize = shell_->GetAspectRatioExtraSize();
double extraWidthPlusFrame = windowFrameSize.width() - contentViewSize.width() + aspectRatioExtraSize.width();
double extraHeightPlusFrame = windowFrameSize.height() - contentViewSize.height() + aspectRatioExtraSize.height();
newSize.width = roundf(((frameSize.height - extraHeightPlusFrame) * aspectRatio) + extraWidthPlusFrame);
// If the new width is less than the frame size use it as the primary constraint. This ensures that the value returned
// by this method will never be larger than the users requested window size.
if (newSize.width <= frameSize.width) {
newSize.height = roundf(((newSize.width - extraWidthPlusFrame) / aspectRatio) + extraHeightPlusFrame);
}
else {
newSize.height = roundf(((frameSize.width - extraWidthPlusFrame) / aspectRatio) + extraHeightPlusFrame);
newSize.width = roundf(((newSize.height - extraHeightPlusFrame) * aspectRatio) + extraWidthPlusFrame);
}
}
return newSize;
}
- (void)windowDidResize:(NSNotification*)notification {
if (!shell_->has_frame())
shell_->ClipWebView();