Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Issue 2374213003: Refactored static_cast'ing of events to use the AsXXXEvent() methods. (Closed)

Created:
4 years, 2 months ago by kylix_rd
Modified:
4 years, 2 months ago
Reviewers:
rjkroege, sadrul
CC:
chromium-reviews, kalyank, ozone-reviews_chromium.org, tdresser+watch_chromium.org
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Use the CHECK'd AsXXXEvent() methods on Event rather than the unsafe static_cast's. Committed: https://crrev.com/d47244cedff9630c4a81e31a285b56cc3dcf263b Cr-Commit-Position: refs/heads/master@{#422830}

Patch Set 1 #

Total comments: 4

Patch Set 2 : Added IsCancelModeEvent() & AsCancelModeEvent() methods to Event #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+38 lines, -19 lines) Patch
M ui/events/event.h View 1 3 chunks +11 lines, -0 lines 0 comments Download
M ui/events/event.cc View 1 1 chunk +10 lines, -0 lines 3 comments Download
M ui/events/event_handler.cc View 1 1 chunk +6 lines, -8 lines 0 comments Download
M ui/events/ozone/evdev/input_injector_evdev_unittest.cc View 1 chunk +2 lines, -2 lines 0 comments Download
M ui/ozone/platform/drm/host/drm_window_host.cc View 2 chunks +2 lines, -2 lines 0 comments Download
M ui/ozone/platform/wayland/wayland_pointer_unittest.cc View 6 chunks +6 lines, -6 lines 0 comments Download
M ui/ozone/platform/wayland/wayland_window_unittest.cc View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 23 (11 generated)
kylix_rd
https://codereview.chromium.org/2374213003/diff/1/ui/events/event_handler.cc File ui/events/event_handler.cc (left): https://codereview.chromium.org/2374213003/diff/1/ui/events/event_handler.cc#oldcode25 ui/events/event_handler.cc:25: // event types. I noticed this comment and had ...
4 years, 2 months ago (2016-09-29 18:12:19 UTC) #6
rjkroege
My preference would be if you added the AsCancelEvent. The rest is a nice cleanup. ...
4 years, 2 months ago (2016-10-03 17:42:45 UTC) #9
kylix_rd
Added xxCancelModeEvent() methods to Event and refactored code in event_handler.cc to use it. https://codereview.chromium.org/2374213003/diff/1/ui/events/event_handler.cc File ...
4 years, 2 months ago (2016-10-03 18:29:04 UTC) #10
rjkroege
lgtm https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc File ui/events/event.cc (right): https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc#newcode291 ui/events/event.cc:291: CancelModeEvent* Event::AsCancelModeEvent() { I know that you're (rightly) ...
4 years, 2 months ago (2016-10-03 22:58:40 UTC) #11
sadrul
lgtm https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc File ui/events/event.cc (right): https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc#newcode291 ui/events/event.cc:291: CancelModeEvent* Event::AsCancelModeEvent() { On 2016/10/03 22:58:40, rjkroege wrote: ...
4 years, 2 months ago (2016-10-04 00:35:04 UTC) #12
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2374213003/20001
4 years, 2 months ago (2016-10-04 14:10:36 UTC) #14
kylix_rd
https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc File ui/events/event.cc (right): https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc#newcode291 ui/events/event.cc:291: CancelModeEvent* Event::AsCancelModeEvent() { On 2016/10/03 22:58:40, rjkroege wrote: > ...
4 years, 2 months ago (2016-10-04 14:12:21 UTC) #15
commit-bot: I haz the power
Try jobs failed on following builders: linux_android_rel_ng on master.tryserver.chromium.android (JOB_FAILED, https://build.chromium.org/p/tryserver.chromium.android/builders/linux_android_rel_ng/builds/153623)
4 years, 2 months ago (2016-10-04 15:30:39 UTC) #17
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2374213003/20001
4 years, 2 months ago (2016-10-04 16:18:17 UTC) #19
commit-bot: I haz the power
Committed patchset #2 (id:20001)
4 years, 2 months ago (2016-10-04 17:00:12 UTC) #20
commit-bot: I haz the power
Patchset 2 (id:??) landed as https://crrev.com/d47244cedff9630c4a81e31a285b56cc3dcf263b Cr-Commit-Position: refs/heads/master@{#422830}
4 years, 2 months ago (2016-10-04 17:03:36 UTC) #22
kylix_rd
4 years, 2 months ago (2016-10-04 20:35:44 UTC) #23
Message was sent while issue was closed.
On 2016/10/04 14:12:21, kylix_rd wrote:
> https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc
> File ui/events/event.cc (right):
> 
>
https://codereview.chromium.org/2374213003/diff/20001/ui/events/event.cc#newc...
> ui/events/event.cc:291: CancelModeEvent* Event::AsCancelModeEvent() {
> On 2016/10/03 22:58:40, rjkroege wrote:
> > I know that you're (rightly) following the pattern of the other As* methods
> but
> > I'm unhappy that these aren't inlined. A function call is a lot slower than
a
> > compile time cast. Can these all of this methods be converted to DCHECK and
be
> > sure to be inlined in a future CL?
> 
> Certainly. I can simply move the method bodies to the header and the compiler
> should use that as a hint to inline, right? I can also add 'inline' to the
decl
> to be sure.

I looked into this and it seems that the reason the methods aren't inlined or
declared in the header is due to the static_cast rule where the compiler checks
object pointer lineage. The compiler cannot perform the downcast because the
descendant classes are only forward declared and the actual definition hasn't
yet been seen.

C:\builds\chromium\src\ui\events\event.h(233,12):  error: static_cast from
'ui::Event *' to 'ui::CancelModeEvent *', which are not related by inheritance,
is not allowed
    return static_cast<CancelModeEvent*>(this);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\builds\chromium\src\ui\events\event.h(33,7):  note: 'CancelModeEvent' is
incomplete
class CancelModeEvent;
      ^

An alternative would be to add a static inline method on each descendant class
that does the downcast. While not universal, there is a similar static method on
LocatedEvent that tries to do just that:

  static const ui::LocatedEvent* FromIfValid(const ui::Event* event) {
    return event && event->IsLocatedEvent() ? event->AsLocatedEvent() : nullptr;
  }

Instead of calling AsXXXXEvent() on the base Event class, each descendant could
provide a method such as this:

  static const ui::LocatedEvent* Cast(const ui::Event* event) {
    DCHECK(event->IsLocatedEvent());
    return static_cast<const LocatedEvent*>(event);
  }

Powered by Google App Engine
This is Rietveld 408576698