More focus behaviour tweaking.

This commit is contained in:
Henrik Rydgård 2014-03-03 12:33:57 +01:00
parent 27bb0b01d3
commit af35f06390
3 changed files with 16 additions and 9 deletions

View File

@ -154,6 +154,15 @@ Point View::GetFocusPosition(FocusDirection dir) {
}
}
bool View::SetFocus() {
if (IsFocusMovementEnabled()) {
if (CanBeFocused()) {
SetFocusedView(this);
return true;
}
return false;
}
}
void Clickable::Click() {
UI::EventParams e;

View File

@ -328,13 +328,7 @@ public:
virtual void ReplaceLayoutParams(LayoutParams *newLayoutParams) { layoutParams_.reset(newLayoutParams); }
const Bounds &GetBounds() const { return bounds_; }
virtual bool SetFocus() {
if (CanBeFocused()) {
SetFocusedView(this);
return true;
}
return false;
}
virtual bool SetFocus();
virtual bool CanBeFocused() const { return true; }
virtual bool SubviewFocused(View *view) { return false; }

View File

@ -431,7 +431,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
}
weightZeroSum += spacing_ * (numVisible - 1);
// Awright, got the sum. Let's take the remaining space after the fixed-size views,
// and distribute among the weighted ones.
if (orientation_ == ORIENT_HORIZONTAL) {
@ -1194,7 +1194,11 @@ void UpdateViewHierarchy(const InputState &input_state, ViewGroup *root) {
lock_guard lock(focusLock);
EnableFocusMovement(true);
if (!GetFocusedView()) {
root->SetFocus();
if (root->GetDefaultFocusView()) {
root->GetDefaultFocusView()->SetFocus();
} else {
root->SetFocus();
}
root->SubviewFocused(GetFocusedView());
} else {
for (size_t i = 0; i < focusMoves.size(); i++) {