getting the current editStateFlags for canCut, canCopy,etc.

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.

getting the current editStateFlags for canCut, canCopy,etc.

Postby jjacobson » Tue Feb 09, 2016 10:02 am

I there a way to query the browser for the ability to perform selection actions like those available in the cef_context_menu_edit_state_flags_t (CanUndo, CanRedo, CanCut, CanPaste, CanCopy, CanDelete, CanSelectAll)? These EditStateFlags come in on the OnBeforeContextmenu but I also need access to this information to enable/disable buttons and items in a file menu bar as well.
jjacobson
Newbie
 
Posts: 5
Joined: Tue Dec 08, 2015 3:48 pm

Re: getting the current editStateFlags for canCut, canCopy,e

Postby magreenblatt » Tue Feb 09, 2016 12:04 pm

There is no way to query the browser for this state currently.

EDIT: You can determine the edit state via JavaScript and provide that information to the browser process.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: getting the current editStateFlags for canCut, canCopy,e

Postby jjacobson » Thu Feb 11, 2016 10:08 am

Thanks for the quick reply the other day.

For anyone else looking this up later.
the javascript document.queryCommandEnabled("cut"); "copy"/"selectAll"/... etc. work well for my purposes.
sending that state any time those values are likely to change adds alot more messages going back to the native code but it doesn't seem to cause any problems.

also note, document.queryCommandEnabled("delete") seems to return 'true' alot more often than it should, (even when the browser context menu says delete is disabled) but checking document.queryCommandEnabled("cut") works as a workaround for most situations.
jjacobson
Newbie
 
Posts: 5
Joined: Tue Dec 08, 2015 3:48 pm

Re: getting the current editStateFlags for canCut, canCopy,e

Postby magreenblatt » Thu Feb 11, 2016 10:52 am

How frequently are you sending the state updates? If you use some reasonable interval (say, 200ms) then your messages will be a drop in the bucket compared to the messages that Chromium sends regularly.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: getting the current editStateFlags for canCut, canCopy,e

Postby BobM » Fri May 13, 2016 12:58 am

I'm trying to implement this - CanPaste/CanCut etc for the application main menu.

Can someone show please how to get the result of document.queryCommandEnabled("cut"); in the native application?

I'm thinking that I need to use window binding.


Code: Select all
void ClientApp::OnContextCreated(
  CefRefPtr<CefBrowser> browser,
  CefRefPtr<CefFrame> frame,
  CefRefPtr<CefV8Context> context)
{
  CefRefPtr<CefV8Value> object = context->GetGlobal();

  CefRefPtr<CefV8Value> canpastebool = CefV8Value::CreateBool(false);

  object->SetValue("canpaste", canpastebool, V8_PROPERTY_ATTRIBUTE_NONE);
}


and in native code....

Code: Select all
  if (m_cefBrowser)
  {
    CefRefPtr<CefFrame> frame = m_cefBrowser->GetMainFrame();
    frame->ExecuteJavaScript("window.canpaste = document.queryCommandEnabled(\"paste\");", frame->GetURL(), 0);
  }


Is this looking close or am I on the wrong track?

Thanks
BobM
Mentor
 
Posts: 72
Joined: Wed May 11, 2016 4:28 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 88 guests