CEFBrowser don't resize properly if container NSView resize

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CEFBrowser don't resize properly if container NSView resize

Postby YvonneDu » Thu Oct 25, 2018 1:49 pm

It is for Mac platform. The CefBrowser will shift from the view and be clipped.

Do anyone know how to solve this?

The reproduce steps are:

Step1. I resize the window, CefBrowser looks good which will show scroll bars when the window becomes small.
https://github.com/yingfangdu/TempFolder/blob/master/Good.jpg

Step2. I resize the container NSView directly, the CefBrowser will squeeze the content (to make it simple, can put the CefBrowser in a NSSplitView and drag & drop the splitter)
https://github.com/yingfangdu/TempFolder/blob/master/ContentSqueeze.jpg

Step3. I resize the window again, the CefBrowser shifts, part of its control is clipped.
https://github.com/yingfangdu/TempFolder/blob/master/LayoutMessup.jpg

I upload a full video here and some screen shots here.
https://github.com/yingfangdu/TempFolder/blob/master/NSViewResizeCefBrowser_2.mov

The chrome version I used:
3.3396.1782.gc368dbf
Chromium 67.0.3396.79
OS Mac OS X
WebKit 537.36 (@161bdad7314804dc8c72f850396fcd696e8863e8)
JavaScript 6.7.288.44
Flash
User Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36
Command Line --lang=en-US --log-
YvonneDu
Techie
 
Posts: 12
Joined: Wed Apr 18, 2018 11:21 am

Re: CEFBrowser don't resize properly if container NSView res

Postby magreenblatt » Thu Oct 25, 2018 1:54 pm

Does the problem reproduce with the CEF sample applications? How does your code differ from those applications?
magreenblatt
Site Admin
 
Posts: 10848
Joined: Fri May 29, 2009 6:57 pm

Re: CEFBrowser don't resize properly if container NSView res

Postby YvonneDu » Thu Oct 25, 2018 3:33 pm

Yes. In cefsample project, simply add the browser to a NSSplitView which is hosted by a NSWindow.
YvonneDu
Techie
 
Posts: 12
Joined: Wed Apr 18, 2018 11:21 am

Re: CEFBrowser don't resize properly if container NSView res

Postby magreenblatt » Thu Oct 25, 2018 3:42 pm

Please post your code changes to cefsimple.
magreenblatt
Site Admin
 
Posts: 10848
Joined: Fri May 29, 2009 6:57 pm

Re: CEFBrowser don't resize properly if container NSView res

Postby YvonneDu » Thu Oct 25, 2018 4:29 pm

Add the below change to simple_app.cc.

Please make CefSimple compile with below files.

If you keep drag & drop the splitter in NSSplitView, you will see the bug.

Another bug you will see is that CefBrowser won't resize along with its parent view. This can be fixed in our product code. While for CefBrowser shifts and is clipped, I have no idea to fix it.

It would be great to get your help.

Code: Select all
void FillSimpleWindowInfo(CefWindowInfo &windowInfo);

void SimpleApp::OnContextInitialized() {
  CEF_REQUIRE_UI_THREAD();

  CefRefPtr<CefCommandLine> command_line =
      CefCommandLine::GetGlobalCommandLine();

#if defined(OS_WIN) || defined(OS_LINUX)
  // Create the browser using the Views framework if "--use-views" is specified
  // via the command-line. Otherwise, create the browser using the native
  // platform framework. The Views framework is currently only supported on
  // Windows and Linux.
  const bool use_views = command_line->HasSwitch("use-views");
#else
  const bool use_views = false;
#endif

  // SimpleHandler implements browser-level callbacks.
  CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views));

  // Specify CEF browser settings here.
  CefBrowserSettings browser_settings;

  std::string url;

  // Check if a "--url=" value was provided via the command-line. If so, use
  // that instead of the default URL.
  url = command_line->GetSwitchValue("url");
  if (url.empty())
    url = "https://www.bing.com";

  if (use_views) {
    // Create the BrowserView.
    CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
        handler, url, browser_settings, NULL, NULL);

    // Create the Window. It will show itself after creation.
    CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view));
  } else {
    // Information used when creating the native window.
    CefWindowInfo window_info;
    FillSimpleWindowInfo(window_info);

#if defined(OS_WIN)
    // On Windows we need to specify certain flags that will be passed to
    // CreateWindowEx().
    window_info.SetAsPopup(NULL, "cefsimple");
#endif

    // Create the first browser window.
    CefBrowserHost::CreateBrowser(window_info, handler, url, browser_settings,
                                  NULL);
  }


Helper.mm
Code: Select all
#import "SimpleWindowController.h"
#include "include/views/cef_window.h"

void FillSimpleWindowInfo(CefWindowInfo &window_info)
{
    SimpleWindowController* controller =  [[SimpleWindowController alloc] initWithWindowNibName:@"SimpleWindow"];
    [controller loadWindow];
    window_info.SetAsChild(controller.Container, 0, 0, controller.Container.bounds.size.width, controller.Container.bounds.size.height);
}


SimpleWindowController.h
Code: Select all

#ifndef SmpleWindowController_h
#define SmpleWindowController_h

#import <Cocoa/Cocoa.h>

@interface SimpleWindowController: NSWindowController

@property (strong, nonatomic) IBOutlet NSView *Container;
@end
#endif /* SmpleWindowController_h */



SimpleWindowController.m
Code: Select all

#import "SimpleWindowController.h"

@implementation SimpleWindowController
@synthesize Container;

@end


SimpleWindow.xib
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="17G65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
    <dependencies>
        <deployment version="101200" identifier="macosx"/>
        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <objects>
        <customObject id="-2" userLabel="File's Owner" customClass="SimpleWindowController">
            <connections>
                <outlet property="Container" destination="cpA-74-HfV" id="2qS-R5-VOJ"/>
            </connections>
        </customObject>
        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
            <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
            <rect key="contentRect" x="196" y="240" width="480" height="270"/>
            <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
            <view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
                <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
                <autoresizingMask key="autoresizingMask"/>
                <subviews>
                    <splitView arrangesAllSubviews="NO" dividerStyle="paneSplitter" translatesAutoresizingMaskIntoConstraints="NO" id="WDo-4l-uQp">
                        <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
                        <subviews>
                            <customView fixedFrame="YES" id="8tN-ZQ-SLL">
                                <rect key="frame" x="0.0" y="0.0" width="480" height="127"/>
                                <autoresizingMask key="autoresizingMask"/>
                            </customView>
                            <customView fixedFrame="YES" id="cpA-74-HfV">
                                <rect key="frame" x="0.0" y="137" width="480" height="133"/>
                                <autoresizingMask key="autoresizingMask"/>
                            </customView>
                        </subviews>
                        <holdingPriorities>
                            <real value="250"/>
                            <real value="250"/>
                        </holdingPriorities>
                    </splitView>
                </subviews>
                <constraints>
                    <constraint firstAttribute="bottom" secondItem="WDo-4l-uQp" secondAttribute="bottom" id="707-l8-sKc"/>
                    <constraint firstAttribute="trailing" secondItem="WDo-4l-uQp" secondAttribute="trailing" id="ORc-xl-dVj"/>
                    <constraint firstItem="WDo-4l-uQp" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" id="qIO-GN-0Cv"/>
                    <constraint firstItem="WDo-4l-uQp" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" id="wIh-bo-CfJ"/>
                </constraints>
            </view>
        </window>
    </objects>
</document>
YvonneDu
Techie
 
Posts: 12
Joined: Wed Apr 18, 2018 11:21 am

Re: CEFBrowser don't resize properly if container NSView res

Postby YvonneDu » Thu Oct 25, 2018 5:38 pm

This looks like not a NSView layout issue. I dumped all sub NSView recursively and the NSLayoutConstraints are not changed between these NSViews.
It looks like CEF's own 'scroll view' issue, the origin point shifts.
YvonneDu
Techie
 
Posts: 12
Joined: Wed Apr 18, 2018 11:21 am

Re: CEFBrowser don't resize properly if container NSView res

Postby Czarek » Fri Oct 26, 2018 12:03 am

You can create a patch file easily with the "git diff" command.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. Connect with me on LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1905
Joined: Sun Nov 06, 2011 2:12 am

Re: CEFBrowser don't resize properly if container NSView res

Postby YvonneDu » Fri Oct 26, 2018 1:34 pm

Sorry, I am new to CEF tools. Usually I consume the binary directly and generate an xcode project to do my develop.

I have tried my best to generate a patch file from 3578 branch which does not include the changes to compile these new added files.

Could you please help me take a look this bug? It would be great to get a quick fix as we cannot ship with this.

Code: Select all
From 912b52b11062179557aa12843136a2c61e54a899 Mon Sep 17 00:00:00 2001
From: Yvonne Du <yingfangdu@gmail.com>
Date: Fri, 26 Oct 2018 11:24:29 -0700
Subject: [PATCH 1/1] Signed-off-by: Yvonne Du

Signed-off-by: Yvonne Du <yingfangdu@gmail.com>
---
 tests/cefsimple/Helper.mm                | 11 +++++
 tests/cefsimple/SimpleWindow.xib         | 52 ++++++++++++++++++++++++
 tests/cefsimple/SimpleWindowController.h | 11 +++++
 tests/cefsimple/SimpleWinowController.m  |  7 ++++
 tests/cefsimple/simple_app.cc            |  3 ++
 5 files changed, 84 insertions(+)
 create mode 100644 tests/cefsimple/Helper.mm
 create mode 100644 tests/cefsimple/SimpleWindow.xib
 create mode 100644 tests/cefsimple/SimpleWindowController.h
 create mode 100644 tests/cefsimple/SimpleWinowController.m

diff --git a/tests/cefsimple/Helper.mm b/tests/cefsimple/Helper.mm
new file mode 100644
index 00000000..1970d5a7
--- /dev/null
+++ b/tests/cefsimple/Helper.mm
@@ -0,0 +1,11 @@
+
+
+#import "SimpleWindowController.h"
+#include "include/views/cef_window.h"
+
+void FillSimpleWindowInfo(CefWindowInfo &window_info)
+{
+    SimpleWindowController* controller =  [[SimpleWindowController alloc] initWithWindowNibName:@"SimpleWindow"];
+    [controller loadWindow];
+    window_info.SetAsChild(controller.Container, 0, 0, controller.Container.bounds.size.width, controller.Container.bounds.size.height);
+}
diff --git a/tests/cefsimple/SimpleWindow.xib b/tests/cefsimple/SimpleWindow.xib
new file mode 100644
index 00000000..01d31967
--- /dev/null
+++ b/tests/cefsimple/SimpleWindow.xib
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="17G65" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+    <dependencies>
+        <deployment version="101200" identifier="macosx"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <objects>
+        <customObject id="-2" userLabel="File's Owner" customClass="SimpleWindowController">
+            <connections>
+                <outlet property="Container" destination="cpA-74-HfV" id="2qS-R5-VOJ"/>
+            </connections>
+        </customObject>
+        <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
+        <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+        <window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
+            <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
+            <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
+            <rect key="contentRect" x="196" y="240" width="480" height="270"/>
+            <rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
+            <view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
+                <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
+                <autoresizingMask key="autoresizingMask"/>
+                <subviews>
+                    <splitView arrangesAllSubviews="NO" dividerStyle="paneSplitter" translatesAutoresizingMaskIntoConstraints="NO" id="WDo-4l-uQp">
+                        <rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
+                        <subviews>
+                            <customView fixedFrame="YES" id="8tN-ZQ-SLL">
+                                <rect key="frame" x="0.0" y="0.0" width="480" height="127"/>
+                                <autoresizingMask key="autoresizingMask"/>
+                            </customView>
+                            <customView fixedFrame="YES" id="cpA-74-HfV">
+                                <rect key="frame" x="0.0" y="137" width="480" height="133"/>
+                                <autoresizingMask key="autoresizingMask"/>
+                            </customView>
+                        </subviews>
+                        <holdingPriorities>
+                            <real value="250"/>
+                            <real value="250"/>
+                        </holdingPriorities>
+                    </splitView>
+                </subviews>
+                <constraints>
+                    <constraint firstAttribute="bottom" secondItem="WDo-4l-uQp" secondAttribute="bottom" id="707-l8-sKc"/>
+                    <constraint firstAttribute="trailing" secondItem="WDo-4l-uQp" secondAttribute="trailing" id="ORc-xl-dVj"/>
+                    <constraint firstItem="WDo-4l-uQp" firstAttribute="leading" secondItem="EiT-Mj-1SZ" secondAttribute="leading" id="qIO-GN-0Cv"/>
+                    <constraint firstItem="WDo-4l-uQp" firstAttribute="top" secondItem="EiT-Mj-1SZ" secondAttribute="top" id="wIh-bo-CfJ"/>
+                </constraints>
+            </view>
+        </window>
+    </objects>
+</document>
diff --git a/tests/cefsimple/SimpleWindowController.h b/tests/cefsimple/SimpleWindowController.h
new file mode 100644
index 00000000..2d66eb31
--- /dev/null
+++ b/tests/cefsimple/SimpleWindowController.h
@@ -0,0 +1,11 @@
+
+#ifndef SmpleWindowController_h
+#define SmpleWindowController_h
+
+#import <Cocoa/Cocoa.h>
+
+@interface SimpleWindowController: NSWindowController
+
+@property (strong, nonatomic) IBOutlet NSView *Container;
+@end
+#endif /* SmpleWindowController_h */
diff --git a/tests/cefsimple/SimpleWinowController.m b/tests/cefsimple/SimpleWinowController.m
new file mode 100644
index 00000000..8d13ef98
--- /dev/null
+++ b/tests/cefsimple/SimpleWinowController.m
@@ -0,0 +1,7 @@
+
+#import "SimpleWindowController.h"
+
+@implementation SimpleWindowController
+@synthesize Container;
+
+@end
diff --git a/tests/cefsimple/simple_app.cc b/tests/cefsimple/simple_app.cc
index 5b0a7ef5..7a168b84 100644
--- a/tests/cefsimple/simple_app.cc
+++ b/tests/cefsimple/simple_app.cc
@@ -13,6 +13,8 @@
 #include "include/wrapper/cef_helpers.h"
 #include "tests/cefsimple/simple_handler.h"
 
+void FillSimpleWindowInfo(CefWindowInfo &windowInfo);
+
 namespace {
 
 // When using the Views framework this object provides the delegate
@@ -94,6 +96,7 @@ void SimpleApp::OnContextInitialized() {
   } else {
     // Information used when creating the native window.
     CefWindowInfo window_info;
+    FillSimpleWindowInfo(window_info);
 
 #if defined(OS_WIN)
     // On Windows we need to specify certain flags that will be passed to
--
2.18.0
YvonneDu
Techie
 
Posts: 12
Joined: Wed Apr 18, 2018 11:21 am

Re: CEFBrowser don't resize properly if container NSView res

Postby joaoneves » Thu Aug 13, 2020 6:20 am

I also hitting this problem? Has anyone reached a solution? Whats the status?
joaoneves
Techie
 
Posts: 14
Joined: Fri Nov 29, 2019 5:45 am

Re: CEFBrowser don't resize properly if container NSView res

Postby danlyke » Fri Apr 16, 2021 3:25 pm

I too am having this problem, posting here so I can be notified should this thread resurrect.
danlyke
Newbie
 
Posts: 1
Joined: Fri Apr 16, 2021 3:21 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 18 guests