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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/input/PastePopupMenu.java

Issue 421173002: Paste PopupMenu gets cropped by StatusBar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified line indentations Created 6 years, 4 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 | « AUTHORS ('k') | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 package org.chromium.content.browser.input; 5 package org.chromium.content.browser.input;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.res.TypedArray; 8 import android.content.res.TypedArray;
9 import android.util.TypedValue; 9 import android.util.TypedValue;
10 import android.view.Gravity; 10 import android.view.Gravity;
11 import android.view.LayoutInflater; 11 import android.view.LayoutInflater;
12 import android.view.View; 12 import android.view.View;
13 import android.view.View.OnClickListener; 13 import android.view.View.OnClickListener;
14 import android.view.ViewGroup; 14 import android.view.ViewGroup;
15 import android.view.ViewGroup.LayoutParams; 15 import android.view.ViewGroup.LayoutParams;
16 import android.widget.PopupWindow; 16 import android.widget.PopupWindow;
17 17
18 /** 18 /**
19 * Paste popup implementation based on TextView.PastePopupMenu. 19 * Paste popup implementation based on TextView.PastePopupMenu.
20 */ 20 */
21 public class PastePopupMenu implements OnClickListener { 21 public class PastePopupMenu implements OnClickListener {
22 private final View mParent; 22 private final View mParent;
23 private final PastePopupMenuDelegate mDelegate; 23 private final PastePopupMenuDelegate mDelegate;
24 private final Context mContext; 24 private final Context mContext;
25 private final PopupWindow mContainer; 25 private final PopupWindow mContainer;
26 private int mRawPositionX; 26 private int mRawPositionX;
27 private int mRawPositionY; 27 private int mRawPositionY;
28 private int mPositionX; 28 private int mPositionX;
29 private int mPositionY; 29 private int mPositionY;
30 private int mStatusBarHeight;
30 private final View[] mPasteViews; 31 private final View[] mPasteViews;
31 private final int[] mPasteViewLayouts; 32 private final int[] mPasteViewLayouts;
32 private final int mLineOffsetY; 33 private final int mLineOffsetY;
33 private final int mWidthOffsetX; 34 private final int mWidthOffsetX;
34 35
35 /** 36 /**
36 * Provider of paste functionality for the given popup. 37 * Provider of paste functionality for the given popup.
37 */ 38 */
38 public interface PastePopupMenuDelegate { 39 public interface PastePopupMenuDelegate {
39 /** 40 /**
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 for (int i = 0; i < attrs.length(); ++i) { 75 for (int i = 0; i < attrs.length(); ++i) {
75 mPasteViewLayouts[i] = attrs.getResourceId(attrs.getIndex(i), 0); 76 mPasteViewLayouts[i] = attrs.getResourceId(attrs.getIndex(i), 0);
76 } 77 }
77 attrs.recycle(); 78 attrs.recycle();
78 79
79 // Convert line offset dips to pixels. 80 // Convert line offset dips to pixels.
80 mLineOffsetY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_D IP, 81 mLineOffsetY = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_D IP,
81 5.0f, mContext.getResources().getDisplayMetrics()); 82 5.0f, mContext.getResources().getDisplayMetrics());
82 mWidthOffsetX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_ DIP, 83 mWidthOffsetX = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_ DIP,
83 30.0f, mContext.getResources().getDisplayMetrics()); 84 30.0f, mContext.getResources().getDisplayMetrics());
85
86 final int statusBarHeightResourceId =
87 mContext.getResources().getIdentifier("status_bar_height", "dime n", "android");
88 if (statusBarHeightResourceId > 0) {
89 mStatusBarHeight =
90 mContext.getResources().getDimensionPixelSize(statusBarHeigh tResourceId);
91 }
84 } 92 }
85 93
86 /** 94 /**
87 * Shows the paste popup at an appropriate location relative to the specifie d position. 95 * Shows the paste popup at an appropriate location relative to the specifie d position.
88 */ 96 */
89 public void showAt(int x, int y) { 97 public void showAt(int x, int y) {
90 if (!canPaste()) return; 98 if (!canPaste()) return;
91 updateContent(true); 99 updateContent(true);
92 positionAt(x, y); 100 positionAt(x, y);
93 } 101 }
(...skipping 30 matching lines...) Expand all
124 int height = contentView.getMeasuredHeight(); 132 int height = contentView.getMeasuredHeight();
125 133
126 mPositionX = (int) (x - width / 2.0f); 134 mPositionX = (int) (x - width / 2.0f);
127 mPositionY = y - height - mLineOffsetY; 135 mPositionY = y - height - mLineOffsetY;
128 136
129 final int[] coords = new int[2]; 137 final int[] coords = new int[2];
130 mParent.getLocationInWindow(coords); 138 mParent.getLocationInWindow(coords);
131 coords[0] += mPositionX; 139 coords[0] += mPositionX;
132 coords[1] += mPositionY; 140 coords[1] += mPositionY;
133 141
142 int minOffsetY = 0;
143 if (mParent.getSystemUiVisibility() == View.SYSTEM_UI_FLAG_VISIBLE) {
144 minOffsetY = mStatusBarHeight;
145 }
146
134 final int screenWidth = mContext.getResources().getDisplayMetrics().widt hPixels; 147 final int screenWidth = mContext.getResources().getDisplayMetrics().widt hPixels;
135 if (coords[1] < 0) { 148 if (coords[1] < minOffsetY) {
136 updateContent(false); 149 updateContent(false);
137 // Update dimensions from new view 150 // Update dimensions from new view
138 contentView = mContainer.getContentView(); 151 contentView = mContainer.getContentView();
139 width = contentView.getMeasuredWidth(); 152 width = contentView.getMeasuredWidth();
140 height = contentView.getMeasuredHeight(); 153 height = contentView.getMeasuredHeight();
141 154
142 // Vertical clipping, move under edited line and to the side of inse rtion cursor 155 // Vertical clipping, move under edited line and to the side of inse rtion cursor
143 // TODO bottom clipping in case there is no system bar 156 // TODO bottom clipping in case there is no system bar
144 coords[1] += height; 157 coords[1] += height;
145 coords[1] += mLineOffsetY; 158 coords[1] += mLineOffsetY;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 208 }
196 209
197 private boolean canPaste() { 210 private boolean canPaste() {
198 return mDelegate.canPaste(); 211 return mDelegate.canPaste();
199 } 212 }
200 213
201 private void paste() { 214 private void paste() {
202 mDelegate.paste(); 215 mDelegate.paste();
203 } 216 }
204 } 217 }
OLDNEW
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698