Commit graph

34 commits

Author SHA1 Message Date
Michael Gratton
0ae633d88f Update existing tests to work with ValaUnit 2020-06-30 17:31:07 +10:00
Michael James Gratton
cbe6e0ba9b Revert "Merge branch 'mjog/558-webkit-shared-process' into 'mainline'"
Revert merge request GNOME/geary!374 for now since the shared process
model breaks old-style WebProcess message handler IPC.

This can be un-reverted when out JS is ported to the new Messages API
that is landing in WebKitGTK 2.28.

This reverts commit e4a5b85698, reversing
changes made to 66f6525480.
2020-02-13 12:56:52 +11:00
James Westman
0eed1bb21a composer: Add font buttons to toolbar
This replaces the menu options in the overflow menu with nicer looking, more
discoverable toolbar buttons. They work much the same way as before.
2020-01-21 19:43:37 -06:00
Michael Gratton
ceb9c9764a Rename ClientWebView to Components.WebView per code style 2019-11-26 14:26:03 +11:00
Michael Gratton
29042bb2d8 Move composer classes into their own namespace
Rename all composer classes prefixed with "Composer" so that the prefix
is a namespace instead. This increases the compartmentalisation of the
classes, making `internal` a useful member modifier and makes them
consistent with the code style guide.
2019-11-17 20:00:02 +11:00
Michael Gratton
1447d1acbc Minimise DOM changes made by ComposerPageState::cleanContent JS
By overriding ComposerPageState::getHtml to accept a parameter that
supports getting HTML with empty composer parts removed, cleanContent
can simply be made to linkify the page, thus allowing a ComposerWidget
to be re-used multiple times when sending an email.
2019-11-17 20:00:01 +11:00
Alex Henrie
feed89225f Don't linkify text near a URL that looks like a URL with a bad protocol 2019-10-22 18:53:18 -06:00
Michael Gratton
69e3cdf9b5 Fix ComposerPageState::containsAttachmentKeyword
Just use ComposerPageState::htmlToText to get the email's main content
without quotes, not some custom code.
2019-10-07 23:49:12 +11:00
Michael Gratton
a8ef91f3a8 ui/composer-web-view.js: Improve keyword detection
Update ComposerPageState.containsKeywords to split on any punctuation,
not just spaces, so that text like "see the attachment." will get
detected.
2019-10-07 23:48:38 +11:00
Michael Gratton
5732d23e98 ui/composer-web-view.js: Add element blacklist to htmlToText
Update ComposerPageState.htmlToText() to allow ignoring certain elements
if needed. Update tests to test the function directly rather than going
through ComposerPageState.toText().
2019-10-07 23:42:49 +11:00
Michael Gratton
2a0de1ce41 Remove Util.Webkit namespace and functions
After the JSC migration they were all a bunch of simple inline
one-liners, so were just making the code more complex than it needed to
be.
2019-07-21 10:46:42 +10:00
Michael Gratton
da6ac828bd Move Geary.JS package into client as Util.JS
The only reason it was in the engine was so it could be used by both
the client and the web extension, without worrying about the
webkit2gtk and webkit2gtk_web_extension packages conflicting. However
it didn't really belong there, and added a dependency for the engine
on javascriptcoregtk which doesn't belong. So this fixes all that.
2019-07-21 10:00:32 +10:00
Michael Gratton
6f1834d696 Port JavaScript code from JS to JSC APIs
JSC is WebKitGTK's supported API going forward and is more
straight-forward than the old JS API, so this simplifies the code and
removes a number of deprecated calls.
2019-07-21 09:01:58 +10:00
Michael Gratton
f14b16fe7a Move WebKitUtil namespace to Util.WebKit 2019-07-20 09:13:43 +10:00
Michael Gratton
12c6bbca56 Fix signature not being updated when composer first opened without one
The ComposerPageState JS object assumed that if no signature was present
when first loaded, that none ever would be. This broke changing the
signature when the composer was opened for an account without one, and
the from account was changed to an account with a sig.

Instead of including the signature as part of the loaded body, always
include just a skeleton signature DIV and ensure the signature is loaded
dynamically after the body has been loaded. Update code and tests to
match this assumption, and add a unit test for updating the sig.

Fixes #309
2019-03-11 12:19:57 +11:00
Alex Henrie
a9efe8fd3a Add plaintext quote marker to blockquote lines in one pass 2019-01-01 17:55:28 -07:00
Alex Henrie
00da60debe Delineate tags a, b, i, and u in plaintext conversion 2018-12-31 11:36:41 -07:00
Michael James Gratton
50f73ff252 Allow test fixtures and test methods to throw errors by default.
* test/testcase.vala (TestCase): Add a generic throws clause to both
  TestMethod and set_up and tear_down, update subclasses.
2018-04-07 09:41:18 +10:00
Michael James Gratton
c427351a9f Update client and JS tests failing after commit 1a918769. 2018-02-08 18:30:08 +11:00
Michael James Gratton
b526b4c3eb Don't insert multiple blank lines in the composer. Bug 778125.
* src/client/composer/composer-web-view.vala
  (ComposerWebView::load_html): Remove spacers around cursor, just add
  them after body and inline quote if present. Update unit tests.
2017-02-07 12:09:29 +11:00
Michael James Gratton
96ffcdb608 Split composer web view up into multiple parts.
This lets us implement changing signatures and deleting bottom-quoted
messages without having to reload the whole view, and makes it possible
to target only the user's content when modifying for send, etc.

* src/client/composer/composer-web-view.vala (ComposerWebView): Move
  composer CSS into composer-web-view.css resource file, load it when
  loading JS resource and add it to the view's user content manager.
  (ComposerWebView::load_html): Split up body, signature and quote into a
  DIV container for each.
  (ComposerWebView::linkify_content): Replaced with ::clean_content,
  which will also tidy up internal markup before sending. Update call
  site and unit test.

* src/engine/rfc822/rfc822-utils.vala (Geary.RFC822.Utils): Remove some
  more obtrusive white space when sending replies/forwards.

* test/client/composer/composer-web-view-test.vala,
  test/js/composer-page-state-test.vala: Update tests to expect new HTML
  and text output from ComposerWebView and use of individual parts for
  composer markup.

* ui/composer-web-view.js (ComposerPageState): Replace messageBody
  property and uses with bodyPart, signaturePart and quotePart. Set these
  content-editable on load. Move listeners from messageBody back to the
  document.body so they also listen for events on the additional
  parts. Keep track of text cursor location within the parts and set a
  class if so, to work around the lack of :focus-inside support.
  (ComposerPageState::updateSignature): Implement by updating the inner
  content of the signature part.
  (ComposerPageState::deleteQuotedMessage): Implement by removing the
  quote part from the DOM tree.
  (ComposerPageState::containsAttachmentKeyword): Consider only the
  bodyPart when scanning for attachments, remove hacks for ignoring the
  signature any any quoted message.
  (ComposerPageState::linkifyContent): Mirror ClientWebView change and
  replace with ::cleanContent. Ensure existing parts have contenteditable
  and focus class removed, remove signature and quote parts if empty.
  (ComposerPageState::getHtml): Generate HTML using clones of the three
  parts, so we can rmeove contenteditable and focus classes without
  modifying the actual DOM.
  (ComposerPageState::selectionChanged): Update focus class on parts as
  needed.
2017-02-01 00:41:45 +11:00
Michael James Gratton
355e4d37c1 Make ClientWebView-based tests execute a bit faster.
* test/client/components/client-web-view-test.vala: New explicit tests
  for init'ing the WebContext and loading default resources.

* test/client/components/client-web-view-test-case.vala:
  Init the WebContext and load resources in the constructor rather than
  fixture setup, so it only happens once per suite, not once per
  test. Update subclasses to do same.

* test/client/composer/composer-web-view-test.vala: Add an explicit test
  for loading ComposerWebView resources.
2017-02-01 00:41:45 +11:00
Michael James Gratton
848558f368 Reenable converting plain text URLs to links in HTML documents.
* src/client/composer/composer-web-view.vala (ComposerWebView): Rename
  ::linkify_document since it really only applies to editor content. Make
  an asyc method so we can wait until its finished. Update call
  sites. Thunk call to JS.

* src/client/web-process/util-composer.vala,
  src/client/web-process/util-webkit.vala: Remove unused code.

* ui/composer-web-view.js (ComposerPageState):  Add ::linkifyContent
  method and ::linkify static method. Add unit tests.
2017-02-01 00:41:44 +11:00
Michael James Gratton
e22ece508c Replace two composer IPC calls for indenting with a single one.
* src/client/composer/composer-web-view.vala (ClientWebView): Replace
  ::undo_blockquote_style with ::indent_line.

* src/client/composer/composer-widget.vala (ComposerWidget::on_indent):
  Call new ::indent_line method, rather than doing a execCommand and a
  second JS thunking call to fix the markup.

* ui/composer-web-view.js: Also replace ::undoBlockquoteStyle with new
  ::indentLine method. Add unit test.
2017-02-01 00:41:44 +11:00
Michael James Gratton
e0bff994fa Reenable composer attachment keyword checking.
* src/client/composer/composer-web-view.vala (ComposerWebView): Add
  ::contains_attachment_keywords that thunks to JS, remove uneeded
  ::get_block_quote_representation method.

* src/client/composer/composer-widget.vala (ComposerWidget): Remove
  attachment keywork checking related code, just call new method on
  editor to do the check.

* src/client/web-process/util-composer.vala,
  src/client/web-process/util-webkit.vala: Remove uneeded code.

* ui/composer-web-view.js (ComposerPageState): Implement new
  ::containsAttachmentKeyword method based on previous code. Add unit
  tests.
2017-02-01 00:41:44 +11:00
Michael James Gratton
dec06d93be Clean up how composer loads content into its web view.
The main gist of this is to ensure that the composer's widgets are
constructed seperately to loading its content, and that we only ever call
ComposerWebView::load_html precisely once per composer instance.

* src/client/composer/composer-widget.vala: Remove referred message,
  quote text and draft flag param from constructor signature, move any
  calls that loaded data from them to new load method. Don't load
  anything into the editor here. Make loading the signature file async,
  and call new ComposerWebView::updateSignature method on the editor to
  update it.
  (ComposerWidget::load): New async message for loading content into the
  composer. Move related code from the constructor and GearyController
  here, make methods that were previously public for that private
  again. Tidy up calls a bit now that we have a single place from which
  to do it all, and can understand the process a bit better.
  (ComposerWidget::on_editor_key_press_event): Don't reload the editor to
  remove the quoted text, call new ComposerWebView::delete_quoted_message
  method on it instead.

* src/client/composer/composer-web-view.vala
  (ComposerWebView): Add ::delete_quoted_message ::update_signature
  methods, thunk to JS.
  (ComposerWebView::load_html): Add quote and is_draft parameters,
  construct HTML for the composer using apporporate spacing here, instead
  of relying on all the disparate parts from doing the right thing.

* src/client/application/geary-controller.vala
  (GearyController::create_compose_widget_async): Load composer content
  after adding it to the widget hierarchy, set focus only after
  everything is set up.

* src/engine/rfc822/rfc822-utils.vala (quote_email_for_reply,
  quote_email_for_forward): Don't add extra padding around quoted parts -
  let callers manage their own whitespace.

* test/client/components/client-web-view-test-case.vala
  (TestCase:load_body_fixture): Make HTML param non-nullable, update
  subclasses.

* ui/composer-web-view.js (ComposerPageState): Add ::updateSignature and
  ::deleteQuotedMessage method stubs.
2017-02-01 00:41:44 +11:00
Michael James Gratton
2b5f94da7d Reenable basic deceptive link highlighting.
* bindings/vapi/javascriptcore-4.0.vapi (Object::get_property): Fix
  return type.

* src/client/conversation-viewer/conversation-message.vala (GtkTemplate):
  Hook up to new deceptive_link_clicked signal, remove old DOM-based
  implementation.

* src/client/conversation-viewer/conversation-web-view.vala
  (ConversationWebView): Add new deceptive_link_clicked signal and
  DeceptiveText enum, listen for deceptiveLinkClicked JS message and fire
  signal when received.

* src/client/util/util-webkit.vala (WebKitUtil): Add to_object util function.

* src/engine/util/util-js.vala (Geary.JS): Add to_object and get_property
  util functions.

* ui/conversation-web-view.js (ConversationPageState) Listen for link
  clicks, check for deceptive text and send message if found. Add unit
  tests for deceptive text check.

* test/js/composer-page-state-test.vala: Move ::run_javascript to parent
  class so new ConversationPageStateTest class can use it, adapt call
  sites to different parent signature.
2017-02-01 00:41:44 +11:00
Michael James Gratton
c476fdc6d1 Replace composer link dialog with a popover.
* src/client/composer/composer-link-popover.vala: New GtkPopover subclass
  for creating/editing links.

* src/client/composer/composer-web-view.vala (EditContext): Add is_link
  and link_uri properties, decode them from the message string, add
  decoding tests.
  (ComposerWebView): Add some as-yet un-implemented methods for
  inserting/deleting links.

* src/client/composer/composer-widget.vala (ComposerWidget): Add
  cursor_url for storing current text cursor link, update it from the
  cursor_context_changed signal param, rename hover_url to pointer_url to
  match. Add link_activated signal to let user's open links they are
  adding, hook that up in the controller. Rename
  ::update_selection_actions to ::update_cursor_actions, since that's a
  little more apt now, also enable insert link action if there is a
  cursor_url set as well as a selection. Remove ::link_dialog, replace
  with ::new_link_popover, hook up the new popover's signals there as
  appropriate.
  (ComposerWidget::on_insert_link): Create and show a lin popover instead
  of a dialog.

* ui/composer-web-view.js: Take note of whther the context node is a link
  and if so, also it's href. Include both when serialsing for the
  cursorContextChanged message. Add serialisation tests.

* ui/composer-link-popover.ui: New UI for link popover.
2017-02-01 00:41:44 +11:00
Michael James Gratton
53caf43fca Replace ad-hoc ComposerWebView cursor signal param w/ structured object.
This lets us notify of more cursor editing context state in the future
without changing the signal signature.

* src/client/composer/composer-web-view.vala (ComposerWebView): Replace
  cursor_style_changed signal and cursorStyleChanged JS message with
  cursor_context_changed signal and cursorContextChanged message, add new
  EditContext inner class and pass as arg to new signal, update call
  sites. Move parsing of JS message to new inner class. Add unit tests,
  fix a font-family bug revealed by tests.

* ui/composer-web-view.js (ComposerPageState): Replace cursorFontFamily
  and cursorFontSize with a cursor context and new EditContext object to
  encapsulate them, update them from a node and serialise them. Add unit
  tests.
2017-02-01 00:41:44 +11:00
Michael James Gratton
f69c461955 Re-enable spell checking in composer.
* src/client/application/geary-config.vala (Configuration): Remove
  spell-check setting, we can just get it from the list of visible
  languages instead. Update the schema.

* src/client/components/client-web-view.vala (WebView::init_web_context):
  Pass in a config object, use that to init WebKit's spell checking on
  the WebContext now that is a global configuration, update it when the
  config changes, update call sites.

* src/client/composer/composer-widget.vala (ComposerWidget): Remove
  WK1-syle spell checking settings prefs.

* src/client/composer/spell-check-popover.vala (SpellCheckPopover): Pass
  a config object in so we don't have to use the global app singleton
  instance.

* src/client/dialogs/preferences-dialog.vala (PreferencesDialog):
  Modernise by converting into a widget template.

* test/client/components/client-web-view-test-case.vala (TestCase):
  Construct a config object as a fixture, use it to init the WebContext
  and make it avalaible to subclasses & update subclasses.

* ui/preferences-dialog.ui: Moved from preferences.dialog, remove spell
  check preference.
2017-02-01 00:41:44 +11:00
Michael James Gratton
977bb2827a Minor code cleanup. 2017-02-01 00:41:43 +11:00
Michael James Gratton
17fda41b85 Fix non-breaking spaces breaking formatting in sent messages.
This ensures that non-breaking space chars (not HTML entities) are
removed from text obtainined from the composer, and moves the F=F text
formatting from JS back to Vala, to minimimse the JS footprint and return
to using the old (working) version again.

* src/client/composer/composer-web-view.vala (ClientWebView::get_text):
  Restore the old F=F formatting code previously in webkit-util, apply it
  to plain text obtained from the composer.

* test/client/components/client-web-view-test-case.vala: New base class
  for tests involving ClientWebView.

* test/client/composer/composer-web-view-test.vala: New tests for
  ComposerWebView::get_html and ::get_text.

* test/js/composer-page-state-test.vala: Reworked to use
  ClientWebViewTestCase, updated tests now that JS is returning
  QUOTE_MARKER-delinated text, not F=F text.

* test/testcase.vala (TestCase): Move ::async_complete and ::async_result
  from ComposerPageStateTest so all test cases can test async code.

* test/CMakeLists.txt: Add new source files.

* test/main.vala (main): Add new test.

* ui/composer-web-view.js: Update doc comments, remove F=F code, break
  out non-breaking space replacement so it can be tested.
2017-02-01 00:41:43 +11:00
Michael James Gratton
772b874def Clean up JavaScriptCore VAPI, client and engine code.
* bindings/vapi/javascriptcore-4.0.vapi: Make JS objects match their JSC
  definitions: move JSValueFoo methods to JS.Value, etc. Update call
  sites.

* src/client/util/util-webkit.vala: Move WebKit-specific common methods
  from ClientWebView here. Update call sites.

* src/engine/util/util-js.vala: Move JSC-specific common methods from
  ClientWebView and ComposerPageStateTest here. Update call sites.

* src/client/web-process/web-process-extension.vala: Check for and handle
  exceptions when calling JS code.

* src/CMakeLists.txt: Add new source files, make WebKit VAPI generation
  and engine compilation depend on JSC.
2017-02-01 00:41:43 +11:00
Michael James Gratton
22de6b122e Fix JS error getting F=F text from ComposerWebView. Add JS unit tests.
* ui/composer-web-view.js (ComposerPageState::resolveNesting): Apply JS
  RegExp globally, to match default GLib RegEx behaviour.

* test/js/composer-page-state-test.vala: New tests covering generation of
  HTML and F=F text from JS ComposerPageState object.

* test/CMakeLists.txt: Add the new test.

* test/main.vala (main): Add a test suite for JS tests, add the new test
  to it.

* src/client/components/client-web-view.vala (ClientWebView): Add a
  reason to the JSError domain for when a JS exception is thrown.

* bindings/vapi/javascriptcore-4.0.vapi (JS::Context): Add JS.Type and
  some additional methods needed for the unit tests. Move most
  GlobalContext methods to Context so we can pass the lowest common
  demominator around.
2017-02-01 00:41:43 +11:00