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

Side by Side Diff: components/exo/pointer.cc

Issue 2338133004: exo: Report tool type with pointer enter event (Closed)
Patch Set: just update new pointer type instead of leave/re-enter Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/exo/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include "ash/common/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "components/exo/pointer_delegate.h" 9 #include "components/exo/pointer_delegate.h"
10 #include "components/exo/pointer_stylus_delegate.h" 10 #include "components/exo/pointer_stylus_delegate.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void Pointer::SetStylusDelegate(PointerStylusDelegate* delegate) { 123 void Pointer::SetStylusDelegate(PointerStylusDelegate* delegate) {
124 stylus_delegate_ = delegate; 124 stylus_delegate_ = delegate;
125 } 125 }
126 126
127 //////////////////////////////////////////////////////////////////////////////// 127 ////////////////////////////////////////////////////////////////////////////////
128 // ui::EventHandler overrides: 128 // ui::EventHandler overrides:
129 129
130 void Pointer::OnMouseEvent(ui::MouseEvent* event) { 130 void Pointer::OnMouseEvent(ui::MouseEvent* event) {
131 Surface* target = GetEffectiveTargetForEvent(event); 131 Surface* target = GetEffectiveTargetForEvent(event);
132 132
133 auto new_pointer_type = pointer_type_;
134 if ((event->flags() & ui::EF_IS_SYNTHESIZED) == 0) {
135 new_pointer_type = event->pointer_details().pointer_type;
136 if (new_pointer_type == ui::EventPointerType::POINTER_TYPE_UNKNOWN)
137 new_pointer_type = ui::EventPointerType::POINTER_TYPE_MOUSE;
138 }
139
133 // If target is different than the current pointer focus then we need to 140 // If target is different than the current pointer focus then we need to
134 // generate enter and leave events. 141 // generate enter and leave events.
135 if (target != focus_) { 142 if (target != focus_) {
136 // First generate a leave event if we currently have a target in focus. 143 // First generate a leave event if we currently have a target in focus.
137 if (focus_) { 144 if (focus_) {
138 delegate_->OnPointerLeave(focus_); 145 delegate_->OnPointerLeave(focus_);
139 focus_->RemoveSurfaceObserver(this); 146 focus_->RemoveSurfaceObserver(this);
140 // Require SetCursor() to be called and cursor to be re-defined in 147 // Require SetCursor() to be called and cursor to be re-defined in
141 // response to each OnPointerEnter() call. 148 // response to each OnPointerEnter() call.
142 focus_->UnregisterCursorProvider(this); 149 focus_->UnregisterCursorProvider(this);
143 focus_ = nullptr; 150 focus_ = nullptr;
144 } 151 }
145 // Second generate an enter event if focus moved to a new target. 152 // Second generate an enter event if focus moved to a new target.
146 if (target) { 153 if (target) {
147 delegate_->OnPointerEnter(target, event->location_f(), 154 delegate_->OnPointerEnter(target, event->location_f(),
148 event->button_flags()); 155 event->button_flags());
149 location_ = event->location_f(); 156 location_ = event->location_f();
150 // Defaulting pointer_type to POINTER_TYPE_MOUSE prevents the tool change 157 if (stylus_delegate_) {
151 // event from being fired when using a mouse. 158 stylus_delegate_->OnPointerToolChange(new_pointer_type);
152 pointer_type_ = ui::EventPointerType::POINTER_TYPE_MOUSE; 159 pointer_type_ = new_pointer_type;
160 }
153 161
154 focus_ = target; 162 focus_ = target;
155 focus_->AddSurfaceObserver(this); 163 focus_->AddSurfaceObserver(this);
156 } 164 }
157 delegate_->OnPointerFrame(); 165 delegate_->OnPointerFrame();
158 } 166 }
159 167
160 // Report changes in pointer type. We treat unknown devices as a mouse. 168 // Report changes in pointer type.
161 auto new_pointer_type = event->pointer_details().pointer_type;
162 if (new_pointer_type == ui::EventPointerType::POINTER_TYPE_UNKNOWN)
163 new_pointer_type = ui::EventPointerType::POINTER_TYPE_MOUSE;
164 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) { 169 if (focus_ && stylus_delegate_ && new_pointer_type != pointer_type_) {
165 stylus_delegate_->OnPointerToolChange(new_pointer_type); 170 stylus_delegate_->OnPointerToolChange(new_pointer_type);
166 pointer_type_ = new_pointer_type; 171 pointer_type_ = new_pointer_type;
167 } 172 }
168 173
169 switch (event->type()) { 174 switch (event->type()) {
170 case ui::ET_MOUSE_PRESSED: 175 case ui::ET_MOUSE_PRESSED:
171 case ui::ET_MOUSE_RELEASED: 176 case ui::ET_MOUSE_RELEASED:
172 if (focus_) { 177 if (focus_) {
173 delegate_->OnPointerButton(event->time_stamp(), 178 delegate_->OnPointerButton(event->time_stamp(),
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 362
358 if (ui_scale != cursor_scale_) { 363 if (ui_scale != cursor_scale_) {
359 gfx::Transform transform; 364 gfx::Transform transform;
360 transform.Scale(ui_scale, ui_scale); 365 transform.Scale(ui_scale, ui_scale);
361 widget_->GetNativeWindow()->SetTransform(transform); 366 widget_->GetNativeWindow()->SetTransform(transform);
362 cursor_scale_ = ui_scale; 367 cursor_scale_ = ui_scale;
363 } 368 }
364 } 369 }
365 370
366 } // namespace exo 371 } // namespace exo
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698