Commit graph

29 commits

Author SHA1 Message Date
Michael Gratton
ceb9c9764a Rename ClientWebView to Components.WebView per code style 2019-11-26 14:26:03 +11:00
Michael Gratton
c27d250032 ClientWebView: Use HTML element's height to determine preferred
Return the scroll height of the HTML element since the BODY
may have margin/border/padding and we want to know
precisely how high the widget needs to be to avoid
scrolling.
2019-07-16 12:00:04 +10:00
Michael Gratton
66fb96181c ClientWebView: Don't update preferred height on height change
Only send an updated height change when the width has changed on
receiving a JavaScript resize event to avoid getting into a feedback
loop, as was happening with email from Mastodon instances.
2019-07-16 12:00:04 +10:00
Rafael Fontenelle
2509c5c4f0 Fix misspellings 2019-05-22 20:47:08 +00:00
Michael Gratton
85fd1bbb0f Remove unused variable 2019-03-06 20:18:44 +11:00
Michael Gratton
9ed81ed759 Remove default instance of ClientWebView's PageState JS object
This default instance was causing double the number of preferred height
events, which was likely creating a race for ConversationWebView. This
might (should?) fix plain text email with quotes sometimes showing up
with a vastly incorrect height.

To ensure that a PageState is constructed properly, make ClientWebView
abstract and use replace the one direct use of the class in the accounts
editor for the signature with a new subclass.

See #283
2019-03-06 20:11:33 +11:00
Michael Gratton
f0418d0477 Rework sending ClientWebView sending preferred height from JS, again
Don't allow any preferred heigh updates to be sent until DOM has been
fully loaded and manupliated (in particular by ConversaionWebView) so
it is vaugely correct when first resized and takes a collapsed quote
heights into account.
2019-02-02 12:39:31 +11:00
Michael Gratton
d8c67ed6d7 Fix message body heigt being inaccurate yet again 2019-01-21 14:19:48 +10:30
Michael Gratton
e9e4e8a277 Make loading conversations olive-buttery smooth
Remove the first/last child hacks from ConversationListBox since the
GTK+ fix for :first-class and :last-class landed in early 3.22.x
releases. Ensure the first expanded email is properly size-allocated
before loading others, that it remains unmoving in the list as other
rows are added, add a loading bar above it when there are more email to
load below it.
2019-01-20 11:44:28 +10:30
Michael James Gratton
d9b94c1c61 Implement editing for the account editor pane. 2018-11-30 23:49:30 +11:00
Michael James Gratton
f7ad510dcc Push WebView editing machinery from the composer to the client.
This allows using the same code for editing account signatures as for the
composer.

* src/client/components/client-web-view.vala (ClientWebView): Move both
  command_stack_changed and document_modified signals here from
  ComposerWebView, since they use the same underlying machinery to
  emit. Move get_html() from ComposerWebView since we want to get to the
  HTML when editing signatures. Override WebView.set_editable() so we can
  enable/disable the signal machinery and hence not get change signals
  emitted when enabling/disabling editing.

* ui/client-web-view.js (PageState): Mirror the changes above made to
  ClientWebView.

* src/meson.build (geary_web_process): Ensure C args are passed through
  web compiling the web extension.
2018-11-30 23:49:30 +11:00
Michael Gratton
1e3fbdc69a Use doc element's scrollHeight as ClientWebView's preferred height
This seems to be a bit more accurate than the previous calculation.
Force the doc element's border to zero as well to make using
scrollHeight more reliable.
2018-10-14 11:55:46 +11:00
Michael Gratton
07c4133b11 Check for ClientWebView preferred height changing in a few more cases
Queue a preferred height check on resize and transition end so we catch
cases where the user resizes the window and transitions cause a height
change after loading has completed, etc.
2018-10-14 11:52:52 +11:00
Michael James Gratton
f1e92feae2 Allow determining when JS has finished loading in ClientWebView.
* src/client/components/client-web-view.vala (ClientWebView): Add
  is_content_loaded property and content_loaded signal, update and fire
  when getting a contentLoaded message from the WebProcess.

* ui/client-web-view.js: Fire the contentLoaded message when loading is
  complete. Add ClientPageStateTest test case to ensure it is working
  fine.

* test/client/components/client-web-view-test-case.vala
  (ClientWebViewTestCase::load_body_fixture): Use is_content_loaded
  rather than is_loading as the test for loading having finished, since
  we're actually interested in when the JS has finished loaded, not the
  resources.
2017-11-16 12:44:57 +11:00
Michael James Gratton
d6ed3e3877 Ensure ClientWebView's preferred height is updated after doc load.
Should help/fix Bug 778025.

* ui/client-web-view.js (PageView::init): Also add a load handler to the
  window, to (strangely) catch the final load event on the
  document. Expand and correct comments a bit.
2017-02-08 00:28:46 +11:00
Michael James Gratton
d74fcd2e2c Fix conversation message not shrinking when collapsing quotes.
* ui/conversation-web-view.js (ConversationPageState::createControllableQuotes):
  Since WK does not want to seem to reduce the value of offsetHeight for
  the HTML element when a quote is collapsed, calculate the difference
  and manually update the preferred height.

* ui/client-web-view.js (PageState::updatePreferredHeight): Allow the new
  preferred height to be passed in as a param.
2017-02-01 00:41:45 +11:00
Michael James Gratton
5ff2d9b908 Calculate ClientWebView to include HTML element margins.
* ui/client-web-view.js (PageState::getPreferredHeight): Compute and use
  top and bottom when determining the height value.

* ui/conversation-web-view.css: Remove onerous style defaults now we
  can deal with HTML elements with margins.
2017-02-01 00:41:44 +11:00
Michael James Gratton
5dfcfe4c8e Update how ClientWebView HTML preferred size changes are sent to the app.
* ui/client-web-view.js (PageState): Use event listeners to send
  coalesced preferred height changes, rather than using polling. Call
  ::load on DOM loaded, not on complete page loaded, so in-place
  mutations take affect ASAP. Replace ::preferredHeightChanged with
  ::updatePreferredHeight method that checks that the height has changed
  before sending the message to the app.

* ui/composer-web-view.js: Remove loaded event handler, it's managed by
  the base class now.

* ui/conversation-web-view.js (ConversationPageState): Rename
  ::updatePreferredHeight to ::pollPreferredHeightUpdate to avoid name
  clash with parent class. Stop polling if no change has occurred after a
  number of repeated checks. Remove loaded event handler, it's managed by
  the base class now.
  (ComposerPageState::createControllableQuotes): Don't update preferred
  height at the end of the call since it will be handled by the DOM load
  event handler.
2017-02-01 00:41:44 +11:00
Michael James Gratton
805a052f1f Don't send JS selectionChanged message unless param value has changed. 2017-02-01 00:41:44 +11:00
Michael James Gratton
617dd45393 Remove use of underscores in client-web-view.js var names. 2017-02-01 00:41:44 +11:00
Michael James Gratton
636e514cda Minor code cleanup.
* src/client/components/client-web-view.vala (ClientWebView): Make some
  unnecessarily internal methods private.

* ui/*.js: Replace "var" with "let" where appropriate - i.e. almost
  everywhere.
2017-02-01 00:41:43 +11:00
Michael James Gratton
8864e2b7a7 Work around rendering quote controller buttons, enable expanding quotes.
* ui/conversation-web-view.js (ConversationPageState): Add
  ::updatePreferredHeight method to waitch for and update the web view's
  preferred height when it changes.
  (ConversationPageState::createControllableQuotes): Create quote
  controllers using the DOM so we can easily attach click handlers to
  it. Attach handlers to toggle the hide class and updated the preferred
  height.

* ui/client-web-view.js (PageState): Add ::getPreferredHeight method, use
  that to determine the preferred height of the page.

* ui/conversation-web-view.css: Import GTK+4 Adwaita button CSS to work
  around WebKitGTK+ Bug 166648. Tweak quote style a bit.
2017-02-01 00:41:43 +11:00
Michael James Gratton
431ebcb35f Re-implement message HTML cleaning in JS in the web extension for WK2.
* ui/conversation-web-view.js: New script, port old HTML cleaning code in
  vala to Javascript as new subclass of PageState. Instantiate that on
  page load.

* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Load and add new JS script for conversations.

* src/client/web-process/util-conversation.vala (Util.Conversation):
  Remove migrated and obsolete code.

* ui/client-web-view.js (PageState): Allow on-load behaviour to be
  overridden in subclasses.

* ui/CMakeLists.txt: Include new JS script.

* ui/conversation-web-view.css: Chase CSS class name changes.
2017-02-01 00:41:43 +11:00
Michael James Gratton
766d55e75d Reimplement selection_changed signal for WK2.
Add a "has_selection" param to avoid a second round-trip to the web
process to determine that.

* src/client/components/client-web-view.vala (ClientWebView): Add a
  selection_changed signal, register a JS message handler for the JS
  equivalent hook up firing the signal.

* src/client/web-process/web-process-extension.vala (GearyWebExtension):
  Send a JS selectionChanged message when the page's selection changes.

* src/client/composer/composer-widget.vala,
  src/client/conversation-viewer/conversation-email.vala,
  src/client/conversation-viewer/conversation-message.vala: Uncomment
  code that relied on the WK1 selection_changed signal, use signal param
  rather than DOM calls.

* ui/client-web-view.js: Implement sending the selectionChanged message.
2017-02-01 00:41:43 +11:00
Michael James Gratton
3068d1b0e5 Integrate preferred height JS code into PageState, tidy it up a bit.
* ui/client-web-view.js: Move emitPreferredHeightChanged() into PageState
  as ::preferredHeightChanged(). Add a explicit constructor, move
  instance properties into that. Add an interval timer to periodically
  update the preferred height until loaded.
2017-02-01 00:41:43 +11:00
Michael James Gratton
d002722a19 Re-implement remote image loading management for WebKit2.
* src/client/components/client-web-view.vala (ClientWebView): Register
  for new remoteImageLoadBlocked message from JS. Add new
  ::remote_image_load_blocked signal to notify when a remote image load
  was blocked. Add ::allow_remote_image_loading and ::load_remote_images
  methods to allow th app to manage image loading state.

* src/client/conversation-viewer/conversation-email.vala
  (ConversationEmail): Determine up front whether the message view should
  load remote images and flag that, rather than passing through the email
  flag and the contact store.

* src/client/conversation-viewer/conversation-message.vala
  (ConversationMessage): Rmeove contact_store and
  always_load_remote_images properties and related code, just let the
  parent email view advise whether remote images should be initially
  loaded and act accordingly. Look up to ClientWebView signal and methods
  to handle manual remote image loading management by the user. Remove
  some obsolete code.

* src/client/web-process/web-process-extension.vala (GearyWebExtension):
  Replace allow_prefix implementation for remote image management with
  explicit signalling to/from the application via JavaScript.

* ui/client-web-view.js: Add a new PageState object, add props and method
  to implement remote image loading management.

* ui/client-web-view-allow-remote-images.js: Monkeypatch to be used when
  remote images should be loaded by default.

* ui/CMakeLists.txt: Include new JS file.

* src/client/conversation-viewer/conversation-web-view.vala,
  src/client/web-process/util-conversation.vala,
  src/client/web-process/util-webkit.vala: Remove obsolete code.
2017-02-01 00:41:43 +11:00
Michael James Gratton
56651ed8c4 Inject ClientWebView script at document start.
* src/client/components/client-web-view.vala
  (ClientWebView::load_app_script): Set script injection time to the
  start of the document load.

* ui/client-web-view.js: Set an onload handler to report back the
  preferred height.
2017-02-01 00:41:43 +11:00
Michael James Gratton
26fe139e97 Initial pass at getting the HTML document's height from the web process.
* bindings/vapi/javascriptcore-4.0.vapi: Add some methods to
  GlobalContext for accessing JSValues as ints.

* src/client/components/client-web-view.vala
  (ClientWebView): Hook up UserContentManager script messages handler and
  handler implementation for "preferredHeightChanged", update the new
  preferred_height prop on the class, and queue a resize. Hook those
  values up to the GTK allocation machinery.
  (ClientWebView::get_int_result): Convenience method for getting an int
  from a JavascriptResult.
  (ClientWebView::get_preferred_height): Report back values as reported
  by messages from the script handler.
  (ClientWebView::register_message_handler): Convenience method for
  registering script messages handlers.

* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Remove now-redundant GTK allocation machinery.

* ui/client-web-view.js: Post a message to preferredHeightChanged when
  the page is sorta-kinda loaded.
2017-02-01 00:41:43 +11:00
Michael James Gratton
09c9a398f7 Load a default app script into ClientWebViews at construction time.
* src/client/application/geary-controller.vala
  (GearyController::open_async): Load the app script for ClientWebView at
  startup.

* src/client/components/client-web-view.vala
  (ClientWebView::ClientWebView): Ensure we actually have a
  UserContentManager instance to work with, add the app script to the
  manager for the instance.
  (ClientWebView::load_scripts): Actually load client-web-view.js.
  (ClientWebView::load_user_stylesheet): Helper method for this class and
  subsclasses for doing the actual script load from the app.

* ui/client-web-view.js: Add boilerplaye for new file.

* ui/CMakeLists.txt: Include client-web-view.js.
2017-02-01 00:41:43 +11:00