out->min_size.reset(new gfx::Size(size));
if (params.Get("max", &size))
out->max_size.reset(new gfx::Size(size));
- if (params.Get("elementSize", &size))
+ if (params.Get("normal", &size))
out->normal_size.reset(new gfx::Size(size));
return true;
}
mainWindow = new BrowserWindow({
width: 800,
height: 600,
- resizable: false,
'auto-hide-menu-bar': true,
'use-content-size': true,
});
@viewInstanceId = params.instanceId
@setSize
+ normal:
+ width: params.elementWidth, height: params.elementHeight
enableAutoSize: params.autosize
min:
width: params.minwidth, height: params.minheight
#define USE(WTF_FEATURE) (defined WTF_USE_##WTF_FEATURE && WTF_USE_##WTF_FEATURE) // NOLINT
#define ENABLE(WTF_FEATURE) (defined ENABLE_##WTF_FEATURE && ENABLE_##WTF_FEATURE) // NOLINT
+#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/renderer/api/atom_api_spell_check_client.h"
#include "content/public/renderer/render_frame.h"
+#include "native_mate/callback.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "third_party/WebKit/public/web/WebDocument.h"
return web_frame_->document().registerEmbedderCustomElement(name, options, c);
}
+void WebFrame::RegisterElementResizeCallback(
+ int element_instance_id,
+ const GuestViewContainer::ResizeCallback& callback) {
+ auto guest_view_container = GuestViewContainer::FromID(element_instance_id);
+ if (guest_view_container)
+ guest_view_container->RegisterElementResizeCallback(callback);
+}
+
void WebFrame::AttachGuest(int id) {
content::RenderFrame::FromWebFrame(web_frame_)->AttachGuest(id);
}
.SetMethod("getZoomFactor", &WebFrame::GetZoomFactor)
.SetMethod("registerEmbedderCustomElement",
&WebFrame::RegisterEmbedderCustomElement)
+ .SetMethod("registerElementResizeCallback",
+ &WebFrame::RegisterElementResizeCallback)
.SetMethod("attachGuest", &WebFrame::AttachGuest)
.SetMethod("setSpellCheckProvider", &WebFrame::SetSpellCheckProvider)
.SetMethod("registerUrlSchemeAsSecure",
#include <string>
+#include "atom/renderer/guest_view_container.h"
#include "base/memory/scoped_ptr.h"
#include "native_mate/handle.h"
#include "native_mate/wrappable.h"
v8::Local<v8::Value> RegisterEmbedderCustomElement(
const base::string16& name, v8::Local<v8::Object> options);
+ void RegisterElementResizeCallback(
+ int element_instance_id,
+ const GuestViewContainer::ResizeCallback& callback);
void AttachGuest(int element_instance_id);
// Set the provider that will be used by SpellCheckClient for spell check.
#include "atom/renderer/guest_view_container.h"
+#include <map>
+
+#include "base/lazy_instance.h"
+
namespace atom {
-GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame) {
+namespace {
+
+using GuestViewContainerMap = std::map<int, GuestViewContainer*>;
+static base::LazyInstance<GuestViewContainerMap> g_guest_view_container_map =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame)
+ : render_frame_(render_frame) {
}
GuestViewContainer::~GuestViewContainer() {
+ if (element_instance_id_ > 0)
+ g_guest_view_container_map.Get().erase(element_instance_id_);
+}
+
+// static
+GuestViewContainer* GuestViewContainer::FromID(int element_instance_id) {
+ GuestViewContainerMap* guest_view_containers =
+ g_guest_view_container_map.Pointer();
+ auto it = guest_view_containers->find(element_instance_id);
+ return it == guest_view_containers->end() ? nullptr : it->second;
+}
+
+void GuestViewContainer::RegisterElementResizeCallback(
+ const ResizeCallback& callback) {
+ element_resize_callback_ = callback;
+}
+
+void GuestViewContainer::SetElementInstanceID(int element_instance_id) {
+ element_instance_id_ = element_instance_id;
+ g_guest_view_container_map.Get().insert(
+ std::make_pair(element_instance_id, this));
+}
+
+void GuestViewContainer::DidResizeElement(const gfx::Size& old_size,
+ const gfx::Size& new_size) {
+ if (element_resize_callback_.is_null())
+ return;
+
+ element_resize_callback_.Run(old_size, new_size);
}
} // namespace atom
#ifndef ATOM_RENDERER_GUEST_VIEW_CONTAINER_H_
#define ATOM_RENDERER_GUEST_VIEW_CONTAINER_H_
+#include "base/callback.h"
#include "content/public/renderer/browser_plugin_delegate.h"
-#include "v8/include/v8.h"
+
+namespace gfx {
+class Size;
+}
namespace atom {
class GuestViewContainer : public content::BrowserPluginDelegate {
public:
+ typedef base::Callback<void(const gfx::Size&, const gfx::Size&)>
+ ResizeCallback;
+
explicit GuestViewContainer(content::RenderFrame* render_frame);
~GuestViewContainer() override;
+ static GuestViewContainer* FromID(int element_instance_id);
+
+ void RegisterElementResizeCallback(const ResizeCallback& callback);
+
+ // content::BrowserPluginDelegate:
+ void SetElementInstanceID(int element_instance_id) final;
+ void DidResizeElement(const gfx::Size& old_size,
+ const gfx::Size& new_size) final;
+
private:
+ int element_instance_id_;
+ content::RenderFrame* render_frame_;
+
+ ResizeCallback element_resize_callback_;
+
DISALLOW_COPY_AND_ASSIGN(GuestViewContainer);
};
@browserPluginNode.removeAttribute webViewConstants.ATTRIBUTE_INTERNALINSTANCEID
@internalInstanceId = parseInt newValue
+ # Track when the element resizes using the element resize callback.
+ webFrame.registerElementResizeCallback @internalInstanceId, @onElementResize.bind(this)
+
return unless @guestInstanceId
guestViewInternal.attachGuest @internalInstanceId, @guestInstanceId, @buildParams()
# changed.
@dispatchEvent webViewEvent
+ onElementResize: (oldSize, newSize) ->
+ # Dispatch the 'resize' event.
+ resizeEvent = new Event('resize', bubbles: true)
+ resizeEvent.oldWidth = oldSize.width
+ resizeEvent.oldHeight = oldSize.height
+ resizeEvent.newWidth = newSize.width
+ resizeEvent.newHeight = newSize.height
+ @dispatchEvent resizeEvent
+
+ if @guestInstanceId
+ guestViewInternal.setSize @guestInstanceId, normal: newSize
+
createGuest: ->
guestViewInternal.createGuest @buildParams(), (guestInstanceId) =>
@attachWindow guestInstanceId
# the on display:block.
css = window.getComputedStyle @webviewNode, null
elementRect = @webviewNode.getBoundingClientRect()
- params.elementSize =
- width: parseInt(elementRect.width) || parseInt(css.getPropertyValue('width'))
- height: parseInt(elementRect.height) || parseInt(css.getPropertyValue('height'))
+ params.elementWidth = parseInt(elementRect.width) ||
+ parseInt(css.getPropertyValue('width'))
+ params.elementHeight = parseInt(elementRect.height) ||
+ parseInt(css.getPropertyValue('height'))
params
attachWindow: (guestInstanceId) ->
-Subproject commit 1696237a3f444f0e33a8947749b4d70f6feb511b
+Subproject commit ad207eeabb0185f74c017e70ca3411d522627ff0