Browse Source

Working on more WebView events

Josh Engebretson 10 years ago
parent
commit
9ac4fb1eaa

+ 2 - 0
Source/Atomic/UI/UIButton.h

@@ -39,6 +39,8 @@ public:
     UIButton(Context* context, bool createWidget = true);
     virtual ~UIButton();
 
+    /// Set if the button's text field should be allowed to squeeze below its preferred size
+    /// If squeezable it may shrink to width 0
     void SetSqueezable(bool value);
 
     void SetEmulationButton(int button);

+ 18 - 0
Source/Atomic/UI/UIWidget.cpp

@@ -591,6 +591,24 @@ double UIWidget::GetValue()
 
 }
 
+void UIWidget::Enable()
+{
+    if (!widget_)
+        return;
+
+    widget_->SetState(WIDGET_STATE_DISABLED, false);
+
+}
+
+void UIWidget::Disable()
+{
+
+    if (!widget_)
+        return;
+
+    widget_->SetState(WIDGET_STATE_DISABLED, true);
+
+}
 
 bool UIWidget::GetState(UI_WIDGET_STATE state)
 {

+ 3 - 0
Source/Atomic/UI/UIWidget.h

@@ -270,6 +270,9 @@ class UIWidget : public Object, public tb::TBWidgetDelegate
 
     void SetTooltip(const String& text);
 
+    void Enable();
+    void Disable();
+
 protected:
 
     void ConvertEvent(UIWidget* handler, UIWidget* target, const tb::TBWidgetEvent &ev, VariantMap& data);

+ 91 - 9
Source/AtomicWebView/WebClient.cpp

@@ -29,7 +29,7 @@ namespace Atomic
 void* GetNSWindowContentView(void* window);
 #endif
 
-class WebClientPrivate : public CefClient, public CefLifeSpanHandler, public CefLoadHandler
+class WebClientPrivate : public CefClient, public CefLifeSpanHandler, public CefLoadHandler, public CefDisplayHandler
 {
     friend class WebClient;
 
@@ -61,15 +61,17 @@ public:
         return this;
     }
 
+    virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
+        return this;
+    }
+
+
     // CefLoadHandler
 
     void OnLoadStart(CefRefPtr<CefBrowser> browser,
                      CefRefPtr<CefFrame> frame) OVERRIDE
     {
-        if (webClient_.Null())
-            return;
-
-        if (!frame->IsMain())
+        if (webClient_.Null() || !frame->IsMain())
             return;
 
         VariantMap eventData;
@@ -88,10 +90,7 @@ public:
                    CefRefPtr<CefFrame> frame,
                    int httpStatusCode) OVERRIDE
     {
-        if (webClient_.Null())
-            return;
-
-        if (!frame->IsMain())
+        if (webClient_.Null() || !frame->IsMain())
             return;
 
         VariantMap eventData;
@@ -123,8 +122,57 @@ public:
                               bool canGoForward) OVERRIDE
     {
 
+        if (webClient_.Null())
+            return;
+
+        VariantMap eventData;
+        eventData[WebViewLoadStateChange::P_CLIENT] = webClient_;
+        eventData[WebViewLoadStateChange::P_LOADING] = isLoading;
+        eventData[WebViewLoadStateChange::P_CANGOBACK] = canGoBack;
+        eventData[WebViewLoadStateChange::P_CANGOFORWARD] = canGoForward;
+
+        webClient_->SendEvent(E_WEBVIEWLOADSTATECHANGE, eventData);
+
+    }
+
+    // CefDisplayHandler
+
+    void OnAddressChange(CefRefPtr<CefBrowser> browser,
+                         CefRefPtr<CefFrame> frame,
+                         const CefString& url) OVERRIDE
+    {
+        if (webClient_.Null() || !frame->IsMain())
+            return;
+
+        VariantMap eventData;
+        eventData[WebViewAddressChange::P_CLIENT] = webClient_;
+
+        String _url;
+        ConvertCEFString(url, _url);
+        eventData[WebViewAddressChange::P_URL] = _url;
+
+        webClient_->SendEvent(E_WEBVIEWADDRESSCHANGE, eventData);
+
     }
 
+    void OnTitleChange(CefRefPtr<CefBrowser> browser,
+                       const CefString& title) OVERRIDE
+    {
+        if (webClient_.Null())
+            return;
+
+        VariantMap eventData;
+        eventData[WebViewTitleChange::P_CLIENT] = webClient_;
+
+        String _title;
+        ConvertCEFString(title, _title);
+        eventData[WebViewTitleChange::P_TITLE] = _title;
+
+        webClient_->SendEvent(E_WEBVIEWTITLECHANGE, eventData);
+
+    }
+
+
     bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
                                   CefProcessId source_process,
                                   CefRefPtr<CefProcessMessage> message) OVERRIDE
@@ -395,6 +443,40 @@ void WebClient::LoadURL(const String& url)
 
 }
 
+void WebClient::GoBack()
+{
+    if (!d_->browser_.get())
+        return;
+
+    d_->browser_->GoBack();
+}
+
+void WebClient::GoForward()
+{
+    if (!d_->browser_.get())
+        return;
+
+    d_->browser_->GoForward();
+}
+
+bool WebClient::IsLoading()
+{
+    if (!d_->browser_.get())
+        return false;
+
+    return d_->browser_->IsLoading();
+}
+
+
+void WebClient::Reload()
+{
+    if (!d_->browser_.get())
+        return;
+
+    d_->browser_->Reload();
+
+}
+
 void WebClient::ShortcutCut()
 {
     if (!d_->browser_.get())

+ 6 - 0
Source/AtomicWebView/WebClient.h

@@ -53,8 +53,14 @@ public:
 
     // Navigation
 
+    bool IsLoading();
+
     /// Load the specified url into the main frame of the browser
     void LoadURL(const String& url);
+    void GoBack();
+    void GoForward();
+
+    void Reload();
 
 private:
 

+ 1 - 1
Source/AtomicWebView/WebString.cpp

@@ -8,7 +8,7 @@ namespace Atomic
 
 bool ConvertCEFString(const CefString& cefString, String& output)
 {
-    output = "Failed to Convert CefString";
+    output = String::EMPTY;
 
     cef_string_utf8_t utf8;
     memset(&utf8, 0, sizeof(utf8));

+ 24 - 0
Source/AtomicWebView/WebViewEvents.h

@@ -6,6 +6,15 @@
 namespace Atomic
 {
 
+/// WebView load state change
+EVENT(E_WEBVIEWLOADSTATECHANGE, WebViewLoadStateChange)
+{
+    PARAM(P_CLIENT, Client);   // WebClient*
+    PARAM(P_LOADING, Loading);   // Boolean
+    PARAM(P_CANGOBACK, CanGoBack);   // Boolean
+    PARAM(P_CANGOFORWARD, CanGoForward);   // Boolean
+}
+
 /// WebView load start
 EVENT(E_WEBVIEWLOADSTART, WebViewLoadStart)
 {
@@ -20,4 +29,19 @@ EVENT(E_WEBVIEWLOADEND, WebViewLoadEnd)
     PARAM(P_URL, Url);   // String
 }
 
+/// WebView address change
+EVENT(E_WEBVIEWADDRESSCHANGE, WebViewAddressChange)
+{
+    PARAM(P_CLIENT, Client);   // WebClient*
+    PARAM(P_URL, Url);   // String
+}
+
+/// WebView title change
+EVENT(E_WEBVIEWTITLECHANGE, WebViewTitleChange)
+{
+    PARAM(P_CLIENT, Client);   // WebClient*
+    PARAM(P_TITLE, Title);   // String
+}
+
+
 }